All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.fusionx.spotify.component.sync.SyncBaseComponent Maven / Gradle / Ivy

The newest version!
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  U previousPage(final PagingObject pagingObject, final Class result) {
        if (Util.isEmpty(pagingObject.getPrevious())) {
            return null;
        }
        return Util.getJsonPojoFromUrl(pagingObject.getPrevious(), result);
    }

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