Package co.fusionx.spotify.component.sync

Source Code of co.fusionx.spotify.component.sync.SyncBaseComponent

package co.fusionx.spotify.component.sync;

import com.fasterxml.jackson.databind.ObjectMapper;

import co.fusionx.spotify.component.BaseComponent;
import co.fusionx.spotify.json.JacksonConverter;
import co.fusionx.spotify.model.PagingObject;
import co.fusionx.spotify.util.Util;
import retrofit.RestAdapter;

public class SyncBaseComponent implements BaseComponent {

    public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    protected static final String SPOTIFY_URL = "https://api.spotify.com/v1";

    protected final RestAdapter mRestAdapter;

    public SyncBaseComponent() {
        mRestAdapter = new RestAdapter.Builder()
                .setEndpoint(SPOTIFY_URL)
                .setConverter(new JacksonConverter(OBJECT_MAPPER))
                .build();
    }

    @Override
    public <T, U> U previousPage(final PagingObject<T> pagingObject, final Class<U> result) {
        if (Util.isEmpty(pagingObject.getPrevious())) {
            return null;
        }
        return Util.getJsonPojoFromUrl(pagingObject.getPrevious(), result);
    }

    @Override
    public <T, U> U nextPage(final PagingObject<T> pagingObject, final Class<U> result) {
        if (Util.isEmpty(pagingObject.getNext())) {
            return null;
        }
        return Util.getJsonPojoFromUrl(pagingObject.getNext(), result);
    }
}
TOP

Related Classes of co.fusionx.spotify.component.sync.SyncBaseComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.