Permalink
Browse files

Adding getNeighbours on UserOperations/UserTemplate and added test

  • Loading branch information...
1 parent db77bb9 commit 70ab02c8c1351c5c1078973b81ceed0fc5c5fc70 @michaellavelle committed Dec 2, 2011
@@ -34,6 +34,9 @@
public List<Shout> getShouts(String userName);
public List<LastFmProfile> getFriends(String userName);
+
+ public List<LastFmProfile> getNeighbours(String userName);
+
public List<Track> getTopTracks(String userName);
@@ -28,6 +28,7 @@
import org.springframework.social.lastfm.api.UserOperations;
import org.springframework.social.lastfm.api.impl.json.LastFmFriendsResponse;
import org.springframework.social.lastfm.api.impl.json.LastFmLovedTracksResponse;
+import org.springframework.social.lastfm.api.impl.json.LastFmNeighboursResponse;
import org.springframework.social.lastfm.api.impl.json.LastFmProfileResponse;
import org.springframework.social.lastfm.api.impl.json.LastFmRecentTracksResponse;
import org.springframework.social.lastfm.api.impl.json.LastFmShoutListResponse;
@@ -200,4 +201,17 @@ public void shout(String userName, String message) {
LastFmFriendsResponse.class).getUserListResponse().getUsers();
}
+ @Override
+ public List<LastFmProfile> getNeighbours(String userName) {
+ Map<String, String> additionalParams = new HashMap<String, String>();
+ additionalParams.put("user", userName);
+
+ LastFmApiMethodParameters methodParameters = new LastFmApiMethodParameters(
+ "user.getneighbours", apiKey, null, null, additionalParams);
+
+ return restTemplate
+ .getForObject(buildLastFmApiUrl(methodParameters),
+ LastFmNeighboursResponse.class).getUserListResponse().getUsers();
+ }
+
}
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * 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 org.springframework.social.lastfm.api.impl.json;
+
+import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * @author Michael Lavelle
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class LastFmNeighboursResponse {
+
+ private LastFmUserListResponse userListResponse;
+
+ @JsonCreator
+ public LastFmNeighboursResponse(
+ @JsonProperty("neighbours") LastFmUserListResponse userListResponse) {
+ this.userListResponse = userListResponse;
+ }
+
+
+ public LastFmUserListResponse getUserListResponse() {
+ return userListResponse;
+ }
+}
@@ -205,6 +205,22 @@ public void getFriends() {
}
@Test
+ public void getNeighbours() {
+
+ mockServer
+ .expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getneighbours&user=mattslip"))
+ .andExpect(method(GET))
+ .andExpect(header("User-Agent", "someUserAgent"))
+ .andRespond(
+ withResponse(jsonResource("testdata/neighbours"),
+ responseHeaders));
+
+ List<LastFmProfile> neighbours = lastFm.userOperations().getNeighbours("mattslip");
+ assertNotNull(neighbours);
+ assertEquals(50,neighbours.size());
+ }
+
+ @Test
public void getFriendsSingleFriendResponse() {
mockServer
Oops, something went wrong.

0 comments on commit 70ab02c

Please sign in to comment.