Permalink
Browse files

Simplified JSON response wrappers and created base classes to a) allo…

…w uniform handling of last fm lists b) speed up introduction of new api methods
  • Loading branch information...
1 parent 70ab02c commit a850e620d01bed51d1b621fffa32efab05c36c57 @michaellavelle committed Dec 3, 2011
Showing with 292 additions and 184 deletions.
  1. +1 −0 src/main/java/org/springframework/social/lastfm/api/impl/LastFmErrorHandler.java
  2. +0 −1 src/main/java/org/springframework/social/lastfm/api/impl/LastFmTemplate.java
  3. +1 −1 src/main/java/org/springframework/social/lastfm/api/impl/TrackTemplate.java
  4. +10 −11 src/main/java/org/springframework/social/lastfm/api/impl/UserTemplate.java
  5. +15 −17 .../social/lastfm/api/impl/json/{LastFmSingleTrackResponse.java → AbstractLastFmNestedResponse.java}
  6. +4 −13 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmFriendsResponse.java
  7. +5 −10 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmLovedTracksResponse.java
  8. +10 −1 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmModule.java
  9. +5 −11 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmNeighboursResponse.java
  10. +3 −9 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmProfileResponse.java
  11. +5 −10 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmRecentTracksResponse.java
  12. +4 −8 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmShoutsResponse.java
  13. +7 −9 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmSimpleTracksResponse.java
  14. +3 −9 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmTopTracksResponse.java
  15. +1 −0 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmTrackMatchesResponse.java
  16. +4 −9 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmTrackSearchResponse.java
  17. +4 −10 src/main/java/org/springframework/social/lastfm/api/impl/json/LastFmTracksResponse.java
  18. +0 −3 src/main/java/org/springframework/social/lastfm/api/impl/json/ShoutMixin.java
  19. +51 −0 src/main/java/org/springframework/social/lastfm/api/impl/json/lists/AbstractLastFmListContainer.java
  20. +2 −4 ...main/java/org/springframework/social/lastfm/api/impl/json/{ → lists}/LastFmShoutListResponse.java
  21. +12 −6 ...g/springframework/social/lastfm/api/impl/json/{ → lists}/LastFmTrackSearchResultListResponse.java
  22. +2 −5 src/main/java/org/springframework/social/lastfm/api/impl/json/{ → lists}/LastFmUserListResponse.java
  23. +5 −13 src/main/java/org/springframework/social/lastfm/api/impl/json/{ → lists}/ShoutListContainer.java
  24. +69 −0 src/main/java/org/springframework/social/lastfm/api/impl/json/lists/SimpleTrackListContainer.java
  25. +5 −8 src/main/java/org/springframework/social/lastfm/api/impl/json/{ → lists}/TrackListContainer.java
  26. +54 −0 ...in/java/org/springframework/social/lastfm/api/impl/json/lists/TrackSearchResultListContainer.java
  27. +8 −16 src/main/java/org/springframework/social/lastfm/api/impl/json/{ → lists}/UserListContainer.java
  28. +2 −0 src/test/resources/org/springframework/social/lastfm/api/testdata/search-results.json
@@ -153,6 +153,7 @@ private String readFully(InputStream in) throws IOException {
while (reader.ready()) {
sb.append(reader.readLine());
}
+ System.out.println(sb.toString());
return sb.toString();
}
@@ -15,7 +15,6 @@
*/
package org.springframework.social.lastfm.api.impl;
-import java.text.SimpleDateFormat;
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
@@ -40,7 +40,7 @@ public TrackTemplate(RestTemplate restTemplate,
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
LastFmTrackSearchResponse.class)
- .getTrackMatchesResponse().getTracksResponse().getTracks();
+ .getNestedResponse().getTracksResponse().getTracks();
}
}
@@ -31,7 +31,6 @@
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;
import org.springframework.social.lastfm.api.impl.json.LastFmShoutsResponse;
import org.springframework.social.lastfm.api.impl.json.LastFmTopTracksResponse;
import org.springframework.social.lastfm.auth.LastFmAccessGrant;
@@ -59,7 +58,7 @@ public LastFmProfile getUserProfile() {
lastFmAccessGrant.getSessionKey());
return restTemplate.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmProfileResponse.class).getLastFmProfile();
+ LastFmProfileResponse.class).getNestedResponse();
}
@@ -72,7 +71,7 @@ public LastFmProfile getUserProfile(String userName) {
"user.getInfo", apiKey, null, null, additionalParams);
return restTemplate.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmProfileResponse.class).getLastFmProfile();
+ LastFmProfileResponse.class).getNestedResponse();
}
@@ -87,8 +86,8 @@ public LastFmProfile getUserProfile(String userName) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmRecentTracksResponse.class).getTracksResponse()
- .getTracks();
+ LastFmRecentTracksResponse.class).getNestedResponse()
+ .getNestedResponse().getTracks();
}
@@ -103,7 +102,7 @@ public LastFmProfile getUserProfile(String userName) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmLovedTracksResponse.class).getTracksResponse()
+ LastFmLovedTracksResponse.class).getNestedResponse().getNestedResponse()
.getTracks();
}
@@ -119,8 +118,8 @@ public LastFmProfile getUserProfile(String userName) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmTopTracksResponse.class).getTracksResponse()
- .getTracks();
+ LastFmTopTracksResponse.class).getNestedResponse()
+ .getNestedResponse().getTracks();
}
@@ -185,7 +184,7 @@ public void shout(String userName, String message) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmShoutsResponse.class).getShoutListResponse().getShouts();
+ LastFmShoutsResponse.class).getNestedResponse().getShouts();
}
@Override
@@ -198,7 +197,7 @@ public void shout(String userName, String message) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmFriendsResponse.class).getUserListResponse().getUsers();
+ LastFmFriendsResponse.class).getNestedResponse().getUsers();
}
@Override
@@ -211,7 +210,7 @@ public void shout(String userName, String message) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmNeighboursResponse.class).getUserListResponse().getUsers();
+ LastFmNeighboursResponse.class).getNestedResponse().getUsers();
}
}
@@ -15,28 +15,26 @@
*/
package org.springframework.social.lastfm.api.impl.json;
-import java.util.List;
-
-import org.codehaus.jackson.annotate.JsonCreator;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.annotate.JsonProperty;
-import org.springframework.social.lastfm.api.Track;
+import java.util.HashMap;
/**
* @author Michael Lavelle
*/
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmSingleTrackResponse {
-
- private List<Track> tracks;
+public abstract class AbstractLastFmNestedResponse<T> extends HashMap<String,T> {
- @JsonCreator
- public LastFmSingleTrackResponse(@JsonProperty("track") List<Track> tracks) {
- this.tracks = tracks;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ private final String responseKey;
+
+ public AbstractLastFmNestedResponse(final String responseKey)
+ {
+ this.responseKey = responseKey;
}
-
- public List<Track> getTracks() {
- return tracks;
+
+ public T getNestedResponse() {
+ return get(responseKey);
}
-
}
@@ -15,26 +15,17 @@
*/
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;
+import org.springframework.social.lastfm.api.impl.json.lists.LastFmUserListResponse;
/**
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmFriendsResponse {
+public class LastFmFriendsResponse extends AbstractLastFmNestedResponse<LastFmUserListResponse>{
- private LastFmUserListResponse userListResponse;
-
- @JsonCreator
- public LastFmFriendsResponse(
- @JsonProperty("friends") LastFmUserListResponse userListResponse) {
- this.userListResponse = userListResponse;
+ public LastFmFriendsResponse() {
+ super("friends");
}
-
- public LastFmUserListResponse getUserListResponse() {
- return userListResponse;
- }
}
@@ -23,17 +23,12 @@
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmLovedTracksResponse {
+public class LastFmLovedTracksResponse extends AbstractLastFmNestedResponse<LastFmTracksResponse>{
- private LastFmTracksResponse tracksResponse;
-
- @JsonCreator
- public LastFmLovedTracksResponse(
- @JsonProperty("lovedtracks") LastFmTracksResponse tracksResponse) {
- this.tracksResponse = tracksResponse;
+ public LastFmLovedTracksResponse() {
+ super("lovedtracks");
}
- public LastFmTracksResponse getTracksResponse() {
- return tracksResponse;
- }
+
+
}
@@ -17,7 +17,6 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.Date;
import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.module.SimpleModule;
@@ -29,6 +28,11 @@
import org.springframework.social.lastfm.api.SimpleTrack;
import org.springframework.social.lastfm.api.Track;
import org.springframework.social.lastfm.api.TrackSearchResult;
+import org.springframework.social.lastfm.api.impl.json.lists.ShoutListContainer;
+import org.springframework.social.lastfm.api.impl.json.lists.SimpleTrackListContainer;
+import org.springframework.social.lastfm.api.impl.json.lists.TrackListContainer;
+import org.springframework.social.lastfm.api.impl.json.lists.TrackSearchResultListContainer;
+import org.springframework.social.lastfm.api.impl.json.lists.UserListContainer;
/**
* Jackson module for setting up mixin annotations on LastFm model types. This
@@ -55,6 +59,11 @@ public void setupModule(SetupContext context) {
context.setMixInAnnotations(TrackListContainer.class, TrackMixin.class);
context.setMixInAnnotations(ShoutListContainer.class, ShoutMixin.class);
context.setMixInAnnotations(UserListContainer.class, LastFmProfileMixin.class);
+ context.setMixInAnnotations(TrackSearchResultListContainer.class, TrackSearchResultMixin.class);
+
+
+
+ context.setMixInAnnotations(SimpleTrackListContainer.class, SimpleTrackMixin.class);
context.setMixInAnnotations(Track.class, TrackMixin.class);
context.setMixInAnnotations(Shout.class, ShoutMixin.class);
@@ -17,24 +17,18 @@
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.annotate.JsonProperty;
+import org.springframework.social.lastfm.api.impl.json.lists.LastFmUserListResponse;
/**
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmNeighboursResponse {
-
- private LastFmUserListResponse userListResponse;
+public class LastFmNeighboursResponse extends AbstractLastFmNestedResponse<LastFmUserListResponse>{
@JsonCreator
- public LastFmNeighboursResponse(
- @JsonProperty("neighbours") LastFmUserListResponse userListResponse) {
- this.userListResponse = userListResponse;
+ public LastFmNeighboursResponse() {
+ super("neighbours");
}
-
- public LastFmUserListResponse getUserListResponse() {
- return userListResponse;
- }
+
}
@@ -24,19 +24,13 @@
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmProfileResponse {
+public class LastFmProfileResponse extends AbstractLastFmNestedResponse<LastFmProfile>{
- private LastFmProfile lastFmProfile;
@JsonCreator
- public LastFmProfileResponse(
- @JsonProperty("user") LastFmProfile lastFmProfile) {
- this.lastFmProfile = lastFmProfile;
-
+ public LastFmProfileResponse() {
+ super("user");
}
- public LastFmProfile getLastFmProfile() {
- return lastFmProfile;
- }
}
@@ -23,17 +23,12 @@
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmRecentTracksResponse {
-
- private LastFmSimpleTracksResponse tracksResponse;
+public class LastFmRecentTracksResponse extends AbstractLastFmNestedResponse<LastFmSimpleTracksResponse> {
@JsonCreator
- public LastFmRecentTracksResponse(
- @JsonProperty("recenttracks") LastFmSimpleTracksResponse tracksResponse) {
- this.tracksResponse = tracksResponse;
- }
-
- public LastFmSimpleTracksResponse getTracksResponse() {
- return tracksResponse;
+ public LastFmRecentTracksResponse()
+ {
+ super("recenttracks");
}
+
}
@@ -18,22 +18,18 @@
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
+import org.springframework.social.lastfm.api.impl.json.lists.LastFmShoutListResponse;
/**
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmShoutsResponse {
+public class LastFmShoutsResponse extends AbstractLastFmNestedResponse<LastFmShoutListResponse> {
- private LastFmShoutListResponse shoutListResponse;
@JsonCreator
- public LastFmShoutsResponse(
- @JsonProperty("shouts") LastFmShoutListResponse shoutListResponse) {
- this.shoutListResponse = shoutListResponse;
+ public LastFmShoutsResponse() {
+ super("shouts");
}
- public LastFmShoutListResponse getShoutListResponse() {
- return shoutListResponse;
- }
}
@@ -15,29 +15,27 @@
*/
package org.springframework.social.lastfm.api.impl.json;
+import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
+import org.springframework.social.lastfm.api.LastFmProfile;
import org.springframework.social.lastfm.api.SimpleTrack;
+import org.springframework.social.lastfm.api.impl.json.lists.SimpleTrackListContainer;
/**
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmSimpleTracksResponse {
-
- private List<SimpleTrack> tracks;
+public class LastFmSimpleTracksResponse extends AbstractLastFmNestedResponse<SimpleTrackListContainer> {
@JsonCreator
- public LastFmSimpleTracksResponse(
- @JsonProperty("track") List<SimpleTrack> tracks) {
- this.tracks = tracks;
+ public LastFmSimpleTracksResponse() {
+ super("track");
}
- public List<SimpleTrack> getTracks() {
- return tracks;
- }
+
}
@@ -23,17 +23,11 @@
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmTopTracksResponse {
-
- private LastFmTracksResponse tracksResponse;
+public class LastFmTopTracksResponse extends AbstractLastFmNestedResponse<LastFmTracksResponse> {
@JsonCreator
- public LastFmTopTracksResponse(
- @JsonProperty("toptracks") LastFmTracksResponse tracksResponse) {
- this.tracksResponse = tracksResponse;
+ public LastFmTopTracksResponse() {
+ super("toptracks");
}
- public LastFmTracksResponse getTracksResponse() {
- return tracksResponse;
- }
}
Oops, something went wrong.

0 comments on commit a850e62

Please sign in to comment.