Skip to content

Commit

Permalink
Added Snapshot class.
Browse files Browse the repository at this point in the history
Added missing request (RemoveTracksFromPlaylist request is still missing).
  • Loading branch information
Wolftein committed Jan 5, 2015
1 parent 53c4656 commit cd16fa9
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 1 deletion.
Expand Up @@ -29,7 +29,11 @@
import me.siegenthaler.spotify.webapi.android.request.ArtistTopTrackRequest;
import me.siegenthaler.spotify.webapi.android.request.AuthoriseClientFlowRequest;
import me.siegenthaler.spotify.webapi.android.request.AuthoriseRefreshRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistAddTracksRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistChangeDetailsRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistCreateRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistListRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistReplaceTracksRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistRequest;
import me.siegenthaler.spotify.webapi.android.request.PlaylistTrackRequest;
import me.siegenthaler.spotify.webapi.android.request.SearchAlbumRequest;
Expand Down Expand Up @@ -237,6 +241,34 @@ public FollowCheckRequest isFollowing(String type, String... ids) {
return addDefaultHeader(new FollowCheckRequest().setType(type).setIds(ids));
}

/**
* (non-doc)
*/
public PlaylistAddTracksRequest addTrackToPlaylist(String user, String playlist) {
return addDefaultHeader(new PlaylistAddTracksRequest().setPlaylist(user, playlist));
}

/**
* (non-doc)
*/
public PlaylistChangeDetailsRequest changePlaylistDetail(String user, String playlist) {
return addDefaultHeader(new PlaylistChangeDetailsRequest().setPlaylist(user, playlist));
}

/**
* (non-doc)
*/
public PlaylistCreateRequest createPlaylist(String user, String playlist) {
return addDefaultHeader(new PlaylistCreateRequest().setUser(user).serName(playlist));
}

/**
* (non-doc)
*/
public PlaylistReplaceTracksRequest replacePlaylistTracks(String user, String playlist) {
return addDefaultHeader(new PlaylistReplaceTracksRequest().setPlaylist(user, playlist));
}

/**
* (non-doc)
*/
Expand Down
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2014 Siegenthaler Solutions.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.siegenthaler.spotify.webapi.android.model;

import com.google.gson.annotations.SerializedName;

/**
* (non-doc)
*/
public class Snapshot {
@SerializedName("snapshot_id")
private String mId;

/**
* (non-doc)
*/
final public String getId() {
return mId;
}
}
Expand Up @@ -46,6 +46,7 @@ public final class AbstractRequest<T> extends Request<T> {
private final Type mType;
private final String mParent;
private final Response.Listener<T> mListener;
private final boolean mJsonBody;

/**
* (non-doc)
Expand All @@ -57,6 +58,7 @@ public AbstractRequest(Builder<?, T> builder) {
this.mHeaders = builder.mHeaders;
this.mParent = builder.mParent;
this.mListener = builder.mListener;
this.mJsonBody = builder.mJsonBody;
setTag(builder.mIdentifier);
}

Expand All @@ -65,7 +67,9 @@ public AbstractRequest(Builder<?, T> builder) {
*/
@Override
final public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=UTF-8";
return mJsonBody
? "application/json; charset=UTF-8"
: "application/x-www-form-urlencoded; charset=UTF-8";
}

/**
Expand Down Expand Up @@ -130,6 +134,7 @@ public static class Builder<J extends Builder, T> {
protected Response.Listener<T> mListener;
protected String mIdentifier;
protected RequestQueue mClient;
protected boolean mJsonBody;

/**
* (non-doc)
Expand All @@ -154,6 +159,14 @@ public Builder(Type type, int method, String parent) {
this.mParent = parent;
}

/**
* (non-doc)
*/
final protected J setJsonBody(boolean isJsonBody) {
mJsonBody = isJsonBody;
return (J) this;
}

/**
* (non-doc)
*/
Expand Down
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2014 Siegenthaler Solutions.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.siegenthaler.spotify.webapi.android.request;

import android.text.TextUtils;

import com.android.volley.Request;

import java.util.Locale;

import me.siegenthaler.spotify.webapi.android.model.Snapshot;

/**
* (non-doc)
*/
public class PlaylistAddTracksRequest extends AbstractRequest.Builder<PlaylistAddTracksRequest, Snapshot> {
/**
* (non-doc)
*/
public PlaylistAddTracksRequest() {
super(Snapshot.class, Request.Method.POST);
}

/**
* (non-doc)
*/
final public PlaylistAddTracksRequest setPlaylist(String user, String playlist) {
return setPath(String.format(Locale.ENGLISH, "/v1/users/%s/playlists/%s/tracks", user, playlist));
}

/**
* (non-doc)
*/
final public PlaylistAddTracksRequest setTracks(int position, String... ids) {
addParameter("position", String.valueOf(position));
return addParameter("uris", TextUtils.join(",", ids));
}
}
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2014 Siegenthaler Solutions.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.siegenthaler.spotify.webapi.android.request;

import com.android.volley.Request;

import java.util.Locale;

/**
* (non-doc)
*/
public class PlaylistChangeDetailsRequest extends AbstractRequest.Builder<PlaylistChangeDetailsRequest, Void> {
/**
* (non-doc)
*/
public PlaylistChangeDetailsRequest() {
super(Void.class, Request.Method.PUT);
setJsonBody(true);
}

/**
* (non-doc)
*/
final public PlaylistChangeDetailsRequest setPlaylist(String user, String playlist) {
return setPath(String.format(Locale.ENGLISH, "/v1/users/%s/playlists/%s", user, playlist));
}

/**
* (non-doc)
*/
final public PlaylistChangeDetailsRequest serName(String name) {
return addParameter("name", name);
}

/**
* (non-doc)
*/
final public PlaylistChangeDetailsRequest setPublic(boolean isPublic) {
return addParameter("public", isPublic ? "true" : "false");
}
}
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2014 Siegenthaler Solutions.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.siegenthaler.spotify.webapi.android.request;

import com.android.volley.Request;

import java.util.Locale;

import me.siegenthaler.spotify.webapi.android.model.Playlist;

/**
* (non-doc)
*/
public class PlaylistCreateRequest extends AbstractRequest.Builder<PlaylistCreateRequest, Playlist> {
/**
* (non-doc)
*/
public PlaylistCreateRequest() {
super(Playlist.class, Request.Method.POST);
setJsonBody(true);
}

/**
* (non-doc)
*/
final public PlaylistCreateRequest setUser(String user) {
return setPath(String.format(Locale.ENGLISH, "/v1/users/%s/playlists", user));
}

/**
* (non-doc)
*/
final public PlaylistCreateRequest serName(String name) {
return addParameter("name", name);
}

/**
* (non-doc)
*/
final public PlaylistCreateRequest setPublic(boolean isPublic) {
return addParameter("public", isPublic ? "true" : "false");
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2014 Siegenthaler Solutions.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.siegenthaler.spotify.webapi.android.request;

import android.text.TextUtils;

import com.android.volley.Request;

import java.util.Locale;

import me.siegenthaler.spotify.webapi.android.model.Snapshot;

/**
* (non-doc)
*/
public class PlaylistReplaceTracksRequest extends AbstractRequest.Builder<PlaylistReplaceTracksRequest, Snapshot> {
/**
* (non-doc)
*/
public PlaylistReplaceTracksRequest() {
super(Snapshot.class, Request.Method.PUT);
}

/**
* (non-doc)
*/
final public PlaylistReplaceTracksRequest setPlaylist(String user, String playlist) {
return setPath(String.format(Locale.ENGLISH, "/v1/users/%s/playlists/%s/tracks", user, playlist));
}

/**
* (non-doc)
*/
final public PlaylistReplaceTracksRequest setTracks(String... ids) {
return addParameter("uris", TextUtils.join(",", ids));
}
}

0 comments on commit cd16fa9

Please sign in to comment.