Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding love and unlove operations to UserOperations/UserTemplate and …

…adding test
  • Loading branch information...
commit d2809a1b976d62cb8ba333290461b646aabc9d8c 1 parent b766632
@michaellavelle authored
View
5 src/main/java/org/springframework/social/lastfm/api/UserOperations.java
@@ -44,6 +44,11 @@
public List<SimpleTrack> getRecentTracks(String userName);
public void scrobble(TrackDescriptor trackDescriptor, Date timestamp);
+
+ public void love(String artistName,String trackName);
+ public void unlove(String artistName,String trackName);
+
+
public void updateNowPlaying(TrackDescriptor trackDescriptor);
View
34 src/main/java/org/springframework/social/lastfm/api/impl/UserTemplate.java
@@ -213,4 +213,38 @@ public void shout(String userName, String message) {
LastFmNeighboursResponse.class).getNestedResponse().getUsers();
}
+ @Override
+ public void love(String artistName, String trackName) {
+
+ requireAuthorization();
+
+ Map<String, String> additionalParams = new HashMap<String, String>();
+ additionalParams.put("track", trackName);
+ additionalParams.put("artist", artistName);
+
+ LastFmApiMethodParameters methodParameters = new LastFmApiMethodParameters(
+ "track.love", apiKey, lastFmAccessGrant.getToken(), secret,
+ lastFmAccessGrant.getSessionKey(), additionalParams);
+
+ restTemplate.postForObject(baseApiUrl, methodParameters, String.class);
+
+ }
+
+ @Override
+ public void unlove(String artistName, String trackName) {
+
+ requireAuthorization();
+
+ Map<String, String> additionalParams = new HashMap<String, String>();
+ additionalParams.put("track", trackName);
+ additionalParams.put("artist", artistName);
+
+ LastFmApiMethodParameters methodParameters = new LastFmApiMethodParameters(
+ "track.unlove", apiKey, lastFmAccessGrant.getToken(), secret,
+ lastFmAccessGrant.getSessionKey(), additionalParams);
+
+ restTemplate.postForObject(baseApiUrl, methodParameters, String.class);
+
+ }
+
}
View
49 src/test/java/org/springframework/social/lastfm/api/UserTemplateTest.java
@@ -340,6 +340,55 @@ public void scrobble() {
someDate);
}
+
+ @Test
+ public void love() {
+
+ mockServer
+ .expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
+ .andExpect(method(POST))
+ .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(
+ body("format=json&api_sig=b50a3b8e66b396f78133d34dc887bda3&api_key=someApiKey&sk=someSessionKey&method=track.love&token=someToken&track=My+track+name&artist=My+artist+name"))
+ .andRespond(
+ withResponse(jsonResource("testdata/status-ok"),
+ responseHeaders));
+
+ lastFm.userOperations().love("My artist name", "My track name");
+
+ }
+
+ @Test(expected = NotAuthorizedException.class)
+ public void love_unauthorized() {
+
+ unauthorizedLastFm.userOperations().love("My artist name", "My track name");
+
+ }
+
+ @Test(expected = NotAuthorizedException.class)
+ public void unlove_unauthorized() {
+
+ unauthorizedLastFm.userOperations().unlove("My artist name", "My track name");
+
+ }
+
+
+ @Test
+ public void unlove() {
+
+ mockServer
+ .expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
+ .andExpect(method(POST))
+ .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(
+ body("format=json&api_sig=929dd59b92e361a3e3ffb7b687856a2b&api_key=someApiKey&sk=someSessionKey&method=track.unlove&token=someToken&track=My+track+name&artist=My+artist+name"))
+ .andRespond(
+ withResponse(jsonResource("testdata/status-ok"),
+ responseHeaders));
+
+ lastFm.userOperations().unlove("My artist name", "My track name");
+
+ }
@Test(expected = NotAuthorizedException.class)
public void scrobble_unauthorized() {
Please sign in to comment.
Something went wrong with that request. Please try again.