kaaes.spotify.webapi.android.models.Pager Java Examples

The following examples show how to use kaaes.spotify.webapi.android.models.Pager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchPager.java    From android-spotify-demo with MIT License 6 votes vote down vote up
public void getMyPlayList(){
    Map<String, Object> options = new HashMap<>();
    options.put(SpotifyService.LIMIT, 30);

    spotifyService.getMyPlaylists(options, new SpotifyCallback<Pager<PlaylistSimple>>() {
        @Override
        public void failure(SpotifyError spotifyError) {
            Log.d("SearchPager", spotifyError.toString());
        }

        @Override
        public void success(Pager<PlaylistSimple> playlistSimplePager, Response response) {
            List<PlaylistSimple> simples = playlistSimplePager.items;

            for(PlaylistSimple simple : simples){
                Log.d("SearchPager", simple.name);
                Log.d("SearchPager", simple.images.get(1).url);
            }

        }
    });
}
 
Example #2
Source File: Pasta.java    From Pasta-for-Spotify with Apache License 2.0 6 votes vote down vote up
@Nullable
public ArrayList<TrackListData> getTracks(AlbumListData data) throws InterruptedException {
    Pager<TrackSimple> tracks = null;
    for (int i = 0; tracks == null && i < PreferenceUtils.getRetryCount(this); i++) {
        try {
            tracks = spotifyService.getAlbum(data.albumId).tracks;
        } catch (Exception e) {
            e.printStackTrace();
            if (StaticUtils.shouldResendRequest(e)) Thread.sleep(200);
            else break;
        }
    }
    if (tracks == null) return null;

    ArrayList<TrackListData> trackList = new ArrayList<>();
    for (TrackSimple track : tracks.items) {
        trackList.add(new TrackListData(track, data.albumName, data.albumId, data.albumImage, data.albumImageLarge));
    }
    return trackList;
}
 
Example #3
Source File: SpotifyServiceTest.java    From spotify-web-api-android with MIT License 6 votes vote down vote up
@Test
public void shouldGetArtistsAlbumsData() throws IOException {
    Type modelType = new TypeToken<Pager<Album>>() {
    }.getType();

    String artistId = "1vCWHaC5f2uS3yhpwWbIA6";
    String body = TestUtils.readTestData("artist-album.json");
    Pager<Album> fixture = mGson.fromJson(body, modelType);

    Response response = TestUtils.getResponseFromModel(fixture, modelType);
    when(mMockClient.execute(argThat(new MatchesId(artistId)))).thenReturn(response);

    Pager<Album> albums = mSpotifyService.getArtistAlbums(artistId);

    this.compareJSONWithoutNulls(body, albums);
}
 
Example #4
Source File: SearchPager.java    From android-spotify-demo with MIT License 5 votes vote down vote up
public void getMyTopTracks(final onCompleteTopTrackListener listener){
    Map<String, Object> options = new HashMap<>();
    options.put(SpotifyService.LIMIT, 10);

    final ListManager listManager = ListManager.getInstance();

    spotifyService.getTopTracks(options, new SpotifyCallback<Pager<Track>>() {
        @Override
        public void failure(SpotifyError spotifyError) {
            Log.d("SearchPager", spotifyError.toString());

            if(listener != null)
                listener.onError(spotifyError);
        }

        @Override
        public void success(Pager<Track> trackPager, Response response) {
            List<Track> tracks = trackPager.items;

            for(Track track : tracks){
                Log.d("SearchPager", track.album.name);
                Log.d("SearchPager", track.album.images.get(1).url);

                listManager.addTopTrack(new TopTrack(track.album.name, track.album.images.get(1).url));

            }

            if(listener != null)
                listener.onComplete();
        }
    });
}
 
Example #5
Source File: SpotifyServiceTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void shouldGetCurrentUserPlaylists() throws Exception {
    final Type modelType = new TypeToken<Pager<PlaylistSimple>>() {}.getType();
    String body = TestUtils.readTestData("user-playlists.json");
    Pager<PlaylistSimple> fixture = mGson.fromJson(body, modelType);

    Response response = TestUtils.getResponseFromModel(fixture, modelType);
    when(mMockClient.execute(isA(Request.class))).thenReturn(response);

    Pager<PlaylistSimple> playlists = mSpotifyService.getMyPlaylists();
    compareJSONWithoutNulls(body, playlists);
}
 
Example #6
Source File: SpotifyServiceTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void shouldGetUserPlaylists() throws Exception {
    final Type modelType = new TypeToken<Pager<PlaylistSimple>>() {}.getType();
    String body = TestUtils.readTestData("user-playlists.json");
    Pager<PlaylistSimple> fixture = mGson.fromJson(body, modelType);

    Response response = TestUtils.getResponseFromModel(fixture, modelType);
    when(mMockClient.execute(isA(Request.class))).thenReturn(response);

    Pager<PlaylistSimple> playlists = mSpotifyService.getPlaylists("test");
    compareJSONWithoutNulls(body, playlists);
}
 
Example #7
Source File: SpotifyServiceTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void shouldGetPlaylistTracks() throws IOException {
    Type modelType = new TypeToken<Pager<PlaylistTrack>>() {
    }.getType();

    String body = TestUtils.readTestData("playlist-tracks.json");
    Pager<PlaylistTrack> fixture = mGson.fromJson(body, modelType);

    Response response = TestUtils.getResponseFromModel(fixture, modelType);
    when(mMockClient.execute(isA(Request.class))).thenReturn(response);

    Pager<PlaylistTrack> playlistTracks = mSpotifyService.getPlaylistTracks("test", "test");
    compareJSONWithoutNulls(body, playlistTracks);
}
 
Example #8
Source File: SpotifyServiceAndroidTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void getUserTopTracks() throws Exception {
    Pager<Track> payload = mService.getTopTracks();

    Request request = new Request.Builder()
            .get()
            .headers(mAuthHeader)
            .url("https://api.spotify.com/v1/me/top/tracks")
            .build();

    Response response = mClient.newCall(request).execute();
    assertEquals(200, response.code());

    assertThat(payload, JsonEquals.jsonEquals(response.body().string()));
}
 
Example #9
Source File: SpotifyServiceAndroidTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void getUserTopArtists() throws Exception {
    Pager<Artist> payload = mService.getTopArtists();

    Request request = new Request.Builder()
            .get()
            .headers(mAuthHeader)
            .url("https://api.spotify.com/v1/me/top/artists")
            .build();

    Response response = mClient.newCall(request).execute();
    assertEquals(200, response.code());

    assertThat(payload, JsonEquals.jsonEquals(response.body().string()));
}
 
Example #10
Source File: SpotifyServiceAndroidTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Test
public void getMyPlaylist() throws Exception {
    Pager<PlaylistSimple> payload = mService.getMyPlaylists();

    Request request = new Request.Builder()
            .get()
            .headers(mAuthHeader)
            .url("https://api.spotify.com/v1/me/playlists")
            .build();

    Response response = mClient.newCall(request).execute();
    assertEquals(200, response.code());

    assertThat(payload, JsonEquals.jsonEquals(response.body().string()));
}
 
Example #11
Source File: SearchPager.java    From android-spotify-demo with MIT License 5 votes vote down vote up
public void getMyTopArtist(final onCompleteTopArtistListener listener){

        Map<String, Object> options = new HashMap<>();
        options.put(SpotifyService.LIMIT, 10);

        final ListManager listManager = ListManager.getInstance();

        spotifyService.getTopArtists(options, new SpotifyCallback<Pager<Artist>>() {
            @Override
            public void failure(SpotifyError spotifyError) {
                Log.d("SearchPager", spotifyError.toString());

                if(listener != null)
                    listener.onError(spotifyError);
            }

            @Override
            public void success(Pager<Artist> artistPager, Response response) {
                List<Artist> mList = artistPager.items;

                for(Artist art : mList){
                    Log.d("SearchPager", art.name);
                    Log.d("SearchPager", art.images.get(1).url);

                    listManager.addTopArtist(new TopArtist(art.name, art.images.get(1).url));
                }

                if(listener != null)
                    listener.onComplete();
                else{
                    Log.d("SearchPager", "What is happening?");
                }
            }
        });
    }
 
Example #12
Source File: Pasta.java    From Pasta-for-Spotify with Apache License 2.0 5 votes vote down vote up
@Nullable
public Pager<PlaylistSimple> getMyPlaylists() throws InterruptedException {
    Pager<PlaylistSimple> playlists = null;
    for (int i = 0; playlists == null && i < PreferenceUtils.getRetryCount(this); i++) {
        try {
            playlists = spotifyService.getMyPlaylists();
        } catch (Exception e) {
            e.printStackTrace();
            if (StaticUtils.shouldResendRequest(e)) Thread.sleep(200);
            else break;
        }
    }
    return playlists;
}
 
Example #13
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the albums saved in the current Spotify user’s “Your Music” library.
 *
 * @param callback Callback method.
 * @see <a href="https://developer.spotify.com/web-api/get-users-saved-albums/">Get a User’s Saved Albums</a>
 */
@GET("/me/albums")
void getMySavedAlbums(Callback<Pager<SavedAlbum>> callback);
 
Example #14
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the songs saved in the current Spotify user’s “Your Music” library.
 *
 * @param options Optional parameters. For list of supported parameters see
 *                <a href="https://developer.spotify.com/web-api/get-users-saved-tracks/">endpoint documentation</a>
 * @return A paginated list of saved tracks
 * @see <a href="https://developer.spotify.com/web-api/get-users-saved-tracks/">Get a User’s Saved Tracks</a>
 */
@GET("/me/tracks")
Pager<SavedTrack> getMySavedTracks(@QueryMap Map<String, Object> options);
 
Example #15
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the albums saved in the current Spotify user’s “Your Music” library.
 *
 * @return A paginated list of saved albums
 * @see <a href="https://developer.spotify.com/web-api/get-users-saved-albums/">Get a User’s Saved Albums</a>
 */
@GET("/me/albums")
Pager<SavedAlbum> getMySavedAlbums();
 
Example #16
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the albums saved in the current Spotify user’s “Your Music” library.
 *
 * @param options  Optional parameters. For list of supported parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-users-saved-albums/">endpoint documentation</a>
 * @param callback Callback method.
 * @see <a href="https://developer.spotify.com/web-api/get-users-saved-albums/">Get a User’s Saved Albums</a>
 */
@GET("/me/albums")
void getMySavedAlbums(@QueryMap Map<String, Object> options, Callback<Pager<SavedAlbum>> callback);
 
Example #17
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the albums saved in the current Spotify user’s “Your Music” library.
 *
 * @param options Optional parameters. For list of supported parameters see
 *                <a href="https://developer.spotify.com/web-api/get-users-saved-albums/">endpoint documentation</a>
 * @return A paginated list of saved albums
 * @see <a href="https://developer.spotify.com/web-api/get-users-saved-albums/">Get a User’s Saved Albums</a>
 */
@GET("/me/albums")
Pager<SavedAlbum> getMySavedAlbums(@QueryMap Map<String, Object> options);
 
Example #18
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top artists based on calculated affinity.
 *
 * @return The objects whose response body contains an artists or tracks object.
 * The object in turn contains a paging object of Artists or Tracks
 */
@GET("/me/top/artists")
Pager<Artist> getTopArtists();
 
Example #19
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top artists based on calculated affinity.
 *
 * @param callback callback method
 */
@GET("/me/top/artists")
void getTopArtists(Callback<Pager<Artist>> callback);
 
Example #20
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top artists based on calculated affinity.
 *
 * @param options Optional parameters. For list of available parameters see
 *                <a href="https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/">endpoint documentation</a>
 * @return The objects whose response body contains an artists or tracks object.
 * The object in turn contains a paging object of Artists or Tracks
 */
@GET("/me/top/artists")
Pager<Artist> getTopArtists(@QueryMap Map<String, Object> options);
 
Example #21
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top artists based on calculated affinity.
 *
 * @param options  Optional parameters. For list of available parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/">endpoint documentation</a>
 * @param callback Callback method
 */
@GET("/me/top/artists")
void getTopArtists(@QueryMap Map<String, Object> options, Callback<Pager<Artist>> callback);
 
Example #22
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @return The objects whose response body contains an artists or tracks object.
 * The object in turn contains a paging object of Artists or Tracks
 */
@GET("/me/top/tracks")
Pager<Track> getTopTracks();
 
Example #23
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @param callback callback method
 */
@GET("/me/top/tracks")
void getTopTracks(Callback<Pager<Track>> callback);
 
Example #24
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @param options Optional parameters. For list of available parameters see
 *                <a href="https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/">endpoint documentation</a>
 * @return The objects whose response body contains an artists or tracks object.
 * The object in turn contains a paging object of Artists or Tracks
 */
@GET("/me/top/tracks")
Pager<Track> getTopTracks(@QueryMap Map<String, Object> options);
 
Example #25
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get the current user’s top tracks based on calculated affinity.
 *
 * @param options  Optional parameters. For list of available parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/">endpoint documentation</a>
 * @param callback Callback method
 */
@GET("/me/top/tracks")
void getTopTracks(@QueryMap Map<String, Object> options, Callback<Pager<Track>> callback);
 
Example #26
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the playlists owned or followed by a Spotify user.
 *
 * @param userId   The user's Spotify user ID.
 * @param options  Optional parameters. For list of supported parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-list-users-playlists/">endpoint documentation</a>
 * @param callback Callback method
 * @see <a href="https://developer.spotify.com/web-api/get-list-users-playlists/">Get a List of a User’s Playlists</a>
 */
@GET("/users/{id}/playlists")
void getPlaylists(@Path("id") String userId, @QueryMap Map<String, Object> options, Callback<Pager<PlaylistSimple>> callback);
 
Example #27
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the playlists owned or followed by the current Spotify user.
 *
 * @param options Optional parameters. For list of supported parameters see
 *                <a href="https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/">endpoint documentation</a>
 * @return List of user's playlists wrapped in a {@code Pager} object
 */
@GET("/me/playlists")
Pager<PlaylistSimple> getMyPlaylists(@QueryMap Map<String, Object> options);
 
Example #28
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the playlists owned or followed by the current Spotify user.
 *
 * @param options  Optional parameters. For list of supported parameters see
 *                 <a href="https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/">endpoint documentation</a>
 * @param callback Callback method.
 */
@GET("/me/playlists")
void getMyPlaylists(@QueryMap Map<String, Object> options, Callback<Pager<PlaylistSimple>> callback);
 
Example #29
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the playlists owned or followed by the current Spotify user.
 *
 * @return List of user's playlists wrapped in a {@code Pager} object
 */
@GET("/me/playlists")
Pager<PlaylistSimple> getMyPlaylists();
 
Example #30
Source File: SpotifyService.java    From spotify-web-api-android with MIT License 2 votes vote down vote up
/**
 * Get a list of the playlists owned or followed by the current Spotify user.
 *
 * @param callback Callback method.
 */
@GET("/me/playlists")
void getMyPlaylists(Callback<Pager<PlaylistSimple>> callback);