Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to get the object currently being played on the user’s Spotify account. #157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jacoco {
toolVersion = "0.7.1.201405082137"
}

def coverageSourceDirs = ['src/main/java' ]
def coverageSourceDirs = ['src/main/java']

task jacocoTestReport(type:JacocoReport, dependsOn: "test") {
task jacocoTestReport(type: JacocoReport, dependsOn: "test") {
group = "Reporting"
description = "Generate Jacoco coverage reports"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import kaaes.spotify.webapi.android.models.AudioFeaturesTracks;
import kaaes.spotify.webapi.android.models.CategoriesPager;
import kaaes.spotify.webapi.android.models.Category;
import kaaes.spotify.webapi.android.models.CurrentlyPlaying;
import kaaes.spotify.webapi.android.models.FeaturedPlaylists;
import kaaes.spotify.webapi.android.models.NewReleases;
import kaaes.spotify.webapi.android.models.Pager;
Expand Down Expand Up @@ -1440,7 +1441,6 @@ public interface SpotifyService {
* Get the current user's followed artists.
*
* @param callback Callback method.
* @return An empty result
* @see <a href="https://developer.spotify.com/web-api/get-followed-artists/">Get User's Followed Artists</a>
*/
@GET("/me/following?type=artist")
Expand All @@ -1463,7 +1463,6 @@ public interface SpotifyService {
* @param options Optional parameters. For list of supported parameters see
* <a href="https://developer.spotify.com/web-api/get-followed-artists/">endpoint documentation</a>
* @param callback Callback method.
* @return An empty result
* @see <a href="https://developer.spotify.com/web-api/get-followed-artists/">Get User's Followed Artists</a>
*/
@GET("/me/following?type=artist")
Expand Down Expand Up @@ -1810,4 +1809,23 @@ public interface SpotifyService {
@GET("/me/top/tracks")
void getTopTracks(@QueryMap Map<String, Object> options, Callback<Pager<Track>> callback);

/**
* Get the object currently being played on the user’s Spotify account.
*
* @param market Optional. An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.
* <a href="https://developer.spotify.com/web-api/get-the-users-currently-playing-track/">endpoint documentation</a>
* @param callback Callback method
*/
@GET("/me/player/currently-playing")
void getCurrentlyPlaying(@Query("market") String market, Callback<CurrentlyPlaying> callback);

/**
* Get the object currently being played on the user’s Spotify account.
*
* @param market Optional. An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.
* <a href="https://developer.spotify.com/web-api/get-the-users-currently-playing-track/">endpoint documentation</a>
* @return Currently Playing Object
*/
@GET("/me/player/currently-playing")
CurrentlyPlaying getCurrentlyPlaying(@Query("market") String market);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package kaaes.spotify.webapi.android.models;

import android.os.Parcel;
import android.os.Parcelable;

/**
* Created by sd2_rails on 9/13/17.
*/

public class CurrentlyPlaying implements Parcelable {

CurrentlyPlayingContext context;
public String timestamp;
public Integer progress_ms;
public boolean is_playing;
public Track item;

protected CurrentlyPlaying(Parcel in) {
context = in.readParcelable(CurrentlyPlayingContext.class.getClassLoader());
timestamp = in.readString();
progress_ms = (Integer) in.readValue(Integer.class.getClassLoader());
is_playing = in.readByte() != 0;
item = in.readParcelable(Track.class.getClassLoader());
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(context, flags);
dest.writeString(timestamp);
dest.writeValue(progress_ms);
dest.writeByte((byte) (is_playing ? 1 : 0));
dest.writeParcelable(item, flags);
}

@Override
public int describeContents() {
return 0;
}

public static final Creator<CurrentlyPlaying> CREATOR = new Creator<CurrentlyPlaying>() {
@Override
public CurrentlyPlaying createFromParcel(Parcel in) {
return new CurrentlyPlaying(in);
}

@Override
public CurrentlyPlaying[] newArray(int size) {
return new CurrentlyPlaying[size];
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package kaaes.spotify.webapi.android.models;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Map;

/**
* Created by sd2_rails on 9/13/17.
*/

public class CurrentlyPlayingContext implements Parcelable {

public String uri;
public String href;
public Map<String, String> external_urls;
public String type;

protected CurrentlyPlayingContext(Parcel in) {
uri = in.readString();
href = in.readString();
external_urls = in.readHashMap(Map.class.getClassLoader());
type = in.readString();
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(uri);
dest.writeString(href);
dest.writeMap(this.external_urls);
dest.writeString(type);
}

@Override
public int describeContents() {
return 0;
}

public static final Creator<CurrentlyPlayingContext> CREATOR = new Creator<CurrentlyPlayingContext>() {
@Override
public CurrentlyPlayingContext createFromParcel(Parcel in) {
return new CurrentlyPlayingContext(in);
}

@Override
public CurrentlyPlayingContext[] newArray(int size) {
return new CurrentlyPlayingContext[size];
}
};
}