Skip to content

Commit dedf213

Browse files
committed
Merge branch 'fix-remove-tracks-v2'
2 parents 2b6147e + d959500 commit dedf213

File tree

8 files changed

+40
-13
lines changed

8 files changed

+40
-13
lines changed

examples/data/playlists/RemoveTracksFromPlaylistExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public class RemoveTracksFromPlaylistExample {
1515
private static final String accessToken = "taHZ2SdB-bPA3FsK3D7ZN5npZS47cMy-IEySVEGttOhXmqaVAIo0ESvTCLjLBifhHOHOIuhFUKPW1WMDP7w6dj3MAZdWT8CLI2MkZaXbYLTeoDvXesf2eeiLYPBGdx8tIwQJKgV8XdnzH_DONk";
1616
private static final String userId = "abbaspotify";
1717
private static final String playlistId = "3AGOiaoRXMSjswCLtuNqv5";
18-
private static final JsonArray tracks = new JsonParser().parse("[\"01iyCAUm8EvOFqVWYJ3dVX\"]").getAsJsonArray();
18+
private static final JsonArray tracks = new JsonParser()
19+
.parse("[{\"uri\":\"spotify:track:01iyCAUm8EvOFqVWYJ3dVX\"}]").getAsJsonArray();
1920

2021
private static final SpotifyApi spotifyApi = new SpotifyApi.Builder()
2122
.setAccessToken(accessToken)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.wrapper.spotify;
2+
3+
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
4+
5+
import java.net.URI;
6+
7+
public class HttpDeleteBody extends HttpEntityEnclosingRequestBase {
8+
public static final String METHOD_NAME = "DELETE";
9+
10+
public HttpDeleteBody() {
11+
}
12+
13+
public HttpDeleteBody(URI uri) {
14+
this.setURI(uri);
15+
}
16+
17+
public HttpDeleteBody(String uri) {
18+
this.setURI(URI.create(uri));
19+
}
20+
21+
public String getMethod() {
22+
return "DELETE";
23+
}
24+
}
25+

src/main/java/com/wrapper/spotify/IHttpManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ String put(URI uri, Header[] headers, HttpEntity body) throws
6262
* @throws IOException In case of networking issues.
6363
* @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause.
6464
*/
65-
String delete(URI uri, Header[] headers) throws
65+
String delete(URI uri, Header[] headers, HttpEntity body) throws
6666
IOException,
6767
SpotifyWebApiException;
6868

src/main/java/com/wrapper/spotify/SpotifyHttpManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,17 @@ public String put(URI uri, Header[] headers, HttpEntity body) throws
171171
}
172172

173173
@Override
174-
public String delete(URI uri, Header[] headers) throws
174+
public String delete(URI uri, Header[] headers, HttpEntity body) throws
175175
IOException,
176176
SpotifyWebApiException {
177177
assert (uri != null);
178178
assert (!uri.toString().equals(""));
179179

180-
final HttpDelete httpDelete = new HttpDelete();
180+
final HttpDeleteBody httpDelete = new HttpDeleteBody();
181181

182182
httpDelete.setURI(uri);
183183
httpDelete.setHeaders(headers);
184+
httpDelete.setEntity(body);
184185

185186
String responseBody = getResponseBody(execute(httpDelete));
186187

src/main/java/com/wrapper/spotify/requests/AbstractRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public String deleteJson() throws
156156
SpotifyWebApiException {
157157
initializeBody();
158158

159-
String json = httpManager.delete(uri, headers.toArray(new Header[headers.size()]));
159+
String json = httpManager.delete(uri, headers.toArray(new Header[headers.size()]), body);
160160

161161
if (json == null || json.equals("")) {
162162
return null;

src/main/java/com/wrapper/spotify/requests/data/playlists/RemoveTracksFromPlaylistRequest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private RemoveTracksFromPlaylistRequest(final Builder builder) {
3535
public SnapshotResult execute() throws
3636
IOException,
3737
SpotifyWebApiException {
38-
return new SnapshotResult.JsonUtil().createModelObject(getJson());
38+
return new SnapshotResult.JsonUtil().createModelObject(deleteJson());
3939
}
4040

4141
/**
@@ -88,11 +88,11 @@ public Builder playlist_id(final String playlist_id) {
8888
* <p>
8989
* There are several ways to specify which tracks to remove, determined by the request parameters.
9090
* Removing all occurrences of specific tracks: <br>
91-
* {@code { "tracks": [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" },
92-
* {"uri": "spotify:track:1301WleyT98MSxVHPZCA6M" }] }} <br>
91+
* {@code [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" },
92+
* {"uri": "spotify:track:1301WleyT98MSxVHPZCA6M" }] } <br>
9393
* Removing a specific occurrence of a track: <br>
94-
* {@code { "tracks": [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "positions": [0,3] },
95-
* { "uri": "spotify:track:1301WleyT98MSxVHPZCA6M", "positions": [7] }] }}
94+
* {@code [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "positions": [0,3] },
95+
* { "uri": "spotify:track:1301WleyT98MSxVHPZCA6M", "positions": [7] }] }
9696
*
9797
* @param tracks Required. An array of objects containing Spotify URIs of the tracks to remove. A maximum of
9898
* 100 objects can be sent at once

src/test/java/com/wrapper/spotify/TestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static IHttpManager returningJson(String jsonFixture) throws Exception {
5555
when(mockedHttpManager.get(any(URI.class), any(Header[].class))).thenReturn(fixture);
5656
when(mockedHttpManager.post(any(URI.class), any(Header[].class), any(HttpEntity.class))).thenReturn(fixture);
5757
when(mockedHttpManager.put(any(URI.class), any(Header[].class), any(HttpEntity.class))).thenReturn(fixture);
58-
when(mockedHttpManager.delete(any(URI.class), any(Header[].class))).thenReturn(fixture);
58+
when(mockedHttpManager.delete(any(URI.class), any(Header[].class), any(HttpEntity.class))).thenReturn(fixture);
5959

6060
return mockedHttpManager;
6161
}

src/test/java/com/wrapper/spotify/requests/data/playlists/RemoveTracksFromPlaylistRequestTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
public class RemoveTracksFromPlaylistRequestTest extends AbstractDataTest<SnapshotResult> {
2020
private final RemoveTracksFromPlaylistRequest defaultRequest = SPOTIFY_API
2121
.removeTracksFromPlaylist(ID_USER, ID_PLAYLIST, new JsonParser()
22-
.parse("[\"" + ID_TRACK + "\",\"" + ID_TRACK + "\"]").getAsJsonArray())
22+
.parse("[{\"uri\":\"" + ID_TRACK + "\"},{\"uri\":\"" + ID_TRACK + "\"}]").getAsJsonArray())
2323
.setHttpManager(
2424
TestUtil.MockedHttpManager.returningJson(
2525
"requests/data/playlists/RemoveTracksFromPlaylistRequest.json"))
@@ -35,7 +35,7 @@ public void shouldComplyWithReference() {
3535
assertHasBodyParameter(
3636
defaultRequest,
3737
"tracks",
38-
"[\"" + ID_TRACK + "\",\"" + ID_TRACK + "\"]");
38+
"[{\"uri\":\"" + ID_TRACK + "\"},{\"uri\":\"" + ID_TRACK + "\"}]");
3939
assertEquals(
4040
"https://api.spotify.com:443/v1/users/abbaspotify/playlists/3AGOiaoRXMSjswCLtuNqv5/tracks",
4141
defaultRequest.getUri().toString());

0 commit comments

Comments
 (0)