Permalink
Browse files

Overriding getOAuth2Version() in SoundCloudTemplate to correct issue …

…with token not being set correctly in request headers. Api restructuring, correction of SoundCloudErrorHandler, and commenting
  • Loading branch information...
1 parent fffb992 commit 5fc8e7919b753533d179825658077f13204feece @michaellavelle committed Sep 8, 2011
Showing with 644 additions and 126 deletions.
  1. +22 −0 .classpath
  2. +13 −0 .project
  3. +5 −0 .settings/org.eclipse.jdt.core.prefs
  4. +1 −0 bin
  5. +11 −0 src/main/java/org/springframework/social/soundcloud/api/MeOperations.java
  6. +15 −0 src/main/java/org/springframework/social/soundcloud/api/ResolveOperations.java
  7. +11 −1 src/main/java/org/springframework/social/soundcloud/api/SoundCloud.java
  8. +0 −1 src/main/java/org/springframework/social/soundcloud/api/SoundCloudProfile.java
  9. +26 −0 src/main/java/org/springframework/social/soundcloud/api/Track.java
  10. +12 −1 src/main/java/org/springframework/social/soundcloud/api/UserOperations.java
  11. +13 −0 src/main/java/org/springframework/social/soundcloud/api/UsersOperations.java
  12. +18 −0 src/main/java/org/springframework/social/soundcloud/api/impl/AbstractSoundCloudOperations.java
  13. +21 −0 ...ain/java/org/springframework/social/soundcloud/api/impl/AbstractSoundCloudResourceOperations.java
  14. +55 −0 src/main/java/org/springframework/social/soundcloud/api/impl/AbstractUserTemplate.java
  15. +22 −0 src/main/java/org/springframework/social/soundcloud/api/impl/MeTemplate.java
  16. +58 −0 src/main/java/org/springframework/social/soundcloud/api/impl/ResolveTemplate.java
  17. +99 −83 src/main/java/org/springframework/social/soundcloud/api/impl/SoundCloudErrorHandler.java
  18. +48 −9 src/main/java/org/springframework/social/soundcloud/api/impl/SoundCloudTemplate.java
  19. +10 −14 src/main/java/org/springframework/social/soundcloud/api/impl/UserTemplate.java
  20. +28 −0 src/main/java/org/springframework/social/soundcloud/api/impl/UsersTemplate.java
  21. +3 −0 src/main/java/org/springframework/social/soundcloud/api/impl/json/SoundCloudModule.java
  22. +0 −4 src/main/java/org/springframework/social/soundcloud/api/impl/json/SoundCloudProfileMixin.java
  23. +14 −0 src/main/java/org/springframework/social/soundcloud/api/impl/json/TrackList.java
  24. +23 −0 src/main/java/org/springframework/social/soundcloud/api/impl/json/TrackMixin.java
  25. +3 −3 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudAdapter.java
  26. +4 −0 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudConnectionFactory.java
  27. +16 −1 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudOAuth2Template.java
  28. +4 −0 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudServiceProvider.java
  29. +10 −9 src/test/java/org/springframework/social/soundcloud/connect/SoundCloudAdapterTest.java
  30. BIN target/classes/org/springframework/social/soundcloud/api/MeOperations.class
  31. BIN target/classes/org/springframework/social/soundcloud/api/ResolveOperations.class
  32. BIN target/classes/org/springframework/social/soundcloud/api/SoundCloud.class
  33. BIN target/classes/org/springframework/social/soundcloud/api/SoundCloudProfile.class
  34. BIN target/classes/org/springframework/social/soundcloud/api/Track.class
  35. BIN target/classes/org/springframework/social/soundcloud/api/UserOperations.class
  36. BIN target/classes/org/springframework/social/soundcloud/api/UsersOperations.class
  37. BIN target/classes/org/springframework/social/soundcloud/api/impl/AbstractSoundCloudOperations.class
  38. BIN ...classes/org/springframework/social/soundcloud/api/impl/AbstractSoundCloudResourceOperations.class
  39. BIN target/classes/org/springframework/social/soundcloud/api/impl/AbstractUserTemplate.class
  40. BIN target/classes/org/springframework/social/soundcloud/api/impl/MeTemplate.class
  41. BIN target/classes/org/springframework/social/soundcloud/api/impl/ResolveTemplate.class
  42. BIN target/classes/org/springframework/social/soundcloud/api/impl/SoundCloudErrorHandler$1.class
  43. BIN target/classes/org/springframework/social/soundcloud/api/impl/SoundCloudErrorHandler$2.class
  44. BIN target/classes/org/springframework/social/soundcloud/api/impl/SoundCloudErrorHandler.class
  45. BIN target/classes/org/springframework/social/soundcloud/api/impl/SoundCloudTemplate.class
  46. BIN target/classes/org/springframework/social/soundcloud/api/impl/UserTemplate.class
  47. BIN target/classes/org/springframework/social/soundcloud/api/impl/UsersTemplate.class
  48. BIN target/classes/org/springframework/social/soundcloud/api/impl/json/SoundCloudModule.class
  49. BIN target/classes/org/springframework/social/soundcloud/api/impl/json/SoundCloudProfileMixin.class
  50. BIN target/classes/org/springframework/social/soundcloud/api/impl/json/TrackList.class
  51. BIN target/classes/org/springframework/social/soundcloud/api/impl/json/TrackMixin.class
  52. BIN target/classes/org/springframework/social/soundcloud/connect/SoundCloudAdapter.class
  53. BIN target/classes/org/springframework/social/soundcloud/connect/SoundCloudConnectionFactory.class
  54. BIN target/classes/org/springframework/social/soundcloud/connect/SoundCloudOAuth2Template.class
  55. BIN target/classes/org/springframework/social/soundcloud/connect/SoundCloudServiceProvider.class
  56. +5 −0 target/maven-archiver/pom.properties
  57. BIN target/spring-social-soundcloud-1.0.0-SNAPSHOT.jar
  58. +70 −0 target/surefire-reports/TEST-org.springframework.social.soundcloud.connect.SoundCloudAdapterTest.xml
  59. +4 −0 target/surefire-reports/org.springframework.social.soundcloud.connect.SoundCloudAdapterTest.txt
  60. BIN target/test-classes/org/springframework/social/soundcloud/connect/SoundCloudAdapterTest$1.class
  61. BIN ...es/org/springframework/social/soundcloud/connect/SoundCloudAdapterTest$TestConnectionValues.class
  62. BIN target/test-classes/org/springframework/social/soundcloud/connect/SoundCloudAdapterTest.class
View
@@ -0,0 +1,22 @@
+<classpath>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
+ <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/codehaus/jackson/jackson-core-asl/1.8.5/jackson-core-asl-1.8.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/codehaus/jackson/jackson-mapper-asl/1.8.5/jackson-mapper-asl-1.8.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mockito/mockito-all/1.8.5/mockito-all-1.8.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.1.0.M2/spring-aop-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-asm/3.1.0.M2/spring-asm-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.1.0.M2/spring-beans-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.1.0.M2/spring-context-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.1.0.M2/spring-core-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.1.0.M2/spring-expression-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/social/spring-social-core/1.0.0.RC3/spring-social-core-1.0.0.RC3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/social/spring-social-test/1.0.0.RC3/spring-social-test-1.0.0.RC3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-test/3.1.0.M2/spring-test-3.1.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-web/3.1.0.M2/spring-web-3.1.0.M2.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+</classpath>
View
@@ -0,0 +1,13 @@
+<projectDescription>
+ <name>spring-social-soundcloud</name>
+ <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,5 @@
+#Sat Sep 03 18:33:41 BST 2011
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
Submodule bin added at fffb99
@@ -0,0 +1,11 @@
+package org.springframework.social.soundcloud.api;
+
+/**
+* Defines operations for interacting with the current authenticated SoundCloud User, a special
+* case of UserOperations
+* @author Michael Lavelle
+*/
+public interface MeOperations extends UserOperations{
+
+
+}
@@ -0,0 +1,15 @@
+package org.springframework.social.soundcloud.api;
+
+
+/**
+* Defines operations for interacting with a SoundCloud resource
+* @author Michael Lavelle
+*/
+public interface ResolveOperations {
+
+ public <T> T resolveSoundCloudResource(String resourceUrl,Class<T> t);
+ public SoundCloudProfile resolveUserProfile(String username);
+ public Track resolveTrack(String trackUrl);
+
+
+}
@@ -1,8 +1,18 @@
package org.springframework.social.soundcloud.api;
+import org.springframework.social.soundcloud.api.impl.SoundCloudTemplate;
+
+/**
+* Interface specifying a basic set of operations for interacting with SoundCloud.
+* Implemented by {@link SoundCloudTemplate}.
+* @author Michael Lavelle
+*/
public interface SoundCloud {
- public UserOperations userOperations();
+ public MeOperations meOperations();
+ public UsersOperations usersOperations();
+ public ResolveOperations resolveOperations();
+
}
@@ -1,7 +1,6 @@
package org.springframework.social.soundcloud.api;
import java.io.Serializable;
-import java.util.List;
/**
* Model class containing a SoundCloud user's profile information.
@@ -0,0 +1,26 @@
+package org.springframework.social.soundcloud.api;
+
+public class Track {
+
+ private String permalinkUrl;
+ private String title;
+ public String getPermalinkUrl() {
+ return permalinkUrl;
+ }
+ public void setPermalinkUrl(String permalinkUrl) {
+ this.permalinkUrl = permalinkUrl;
+ }
+ public String getTitle() {
+ return title;
+ }
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public Track(String permalinkUrl,String title)
+ {
+ this.title = title;
+ this.permalinkUrl = permalinkUrl;
+ }
+
+}
@@ -1,7 +1,18 @@
package org.springframework.social.soundcloud.api;
+import java.util.List;
+
+/**
+* Defines operations for interacting with a SoundCloud User
+* @author Michael Lavelle
+*/
public interface UserOperations {
-
+
public SoundCloudProfile getUserProfile();
+ public void updateUserProfile(SoundCloudProfile profile);
+ public List<Track> getFavorites();
+ public List<Track> getTracks();
+ public void favoriteTrack(long trackId);
+
}
@@ -0,0 +1,13 @@
+package org.springframework.social.soundcloud.api;
+
+/**
+* Defines a means of obtaining UserOperations for a given SoundCloud user id
+* @author Michael Lavelle
+*/
+public interface UsersOperations {
+
+ public UserOperations userOperations(long userId);
+ public UserOperations userOperations(String username);
+
+
+}
@@ -1,5 +1,23 @@
package org.springframework.social.soundcloud.api.impl;
+import org.springframework.web.client.RestTemplate;
+
public abstract class AbstractSoundCloudOperations {
+
+ protected final RestTemplate restTemplate;
+ protected final boolean isAuthorizedForUser;
+ public AbstractSoundCloudOperations(RestTemplate restTemplate, boolean isAuthorizedForUser) {
+ this.restTemplate = restTemplate;
+ this.isAuthorizedForUser = isAuthorizedForUser;
+ }
+
+ protected String getApiBaseUrl()
+ {
+ return "https://api.soundcloud.com";
+ }
+
+
+
+
}
@@ -0,0 +1,21 @@
+package org.springframework.social.soundcloud.api.impl;
+
+import org.springframework.web.client.RestTemplate;
+
+public abstract class AbstractSoundCloudResourceOperations extends AbstractSoundCloudOperations{
+
+ public AbstractSoundCloudResourceOperations(RestTemplate restTemplate, boolean isAuthorizedForUser) {
+ super(restTemplate,isAuthorizedForUser);
+ }
+
+ protected abstract String getApiResourceBaseUrl();
+
+ protected String getApiResourceUrl(String resourcePath)
+ {
+ return getApiResourceBaseUrl() + resourcePath;
+ }
+
+
+
+
+}
@@ -0,0 +1,55 @@
+package org.springframework.social.soundcloud.api.impl;
+
+import java.util.List;
+
+import org.springframework.social.soundcloud.api.SoundCloudProfile;
+import org.springframework.social.soundcloud.api.Track;
+import org.springframework.social.soundcloud.api.UserOperations;
+import org.springframework.social.soundcloud.api.impl.json.TrackList;
+import org.springframework.web.client.RestTemplate;
+
+public abstract class AbstractUserTemplate extends AbstractSoundCloudResourceOperations implements UserOperations {
+
+ public AbstractUserTemplate(RestTemplate restTemplate,
+ boolean isAuthorizedForUser) {
+ super(restTemplate, isAuthorizedForUser);
+ }
+ protected abstract String getUsersResourcePrefix();
+
+ @Override
+ protected String getApiResourceBaseUrl() {
+ return getApiBaseUrl() + getUsersResourcePrefix();
+ }
+
+
+ @Override
+ public void favoriteTrack(long trackId) {
+ restTemplate.put(getApiResourceUrl("/favorites/" + trackId),null);
+
+ }
+
+
+ @Override
+ public void updateUserProfile(SoundCloudProfile profile) {
+ restTemplate.put(getApiResourceUrl(""), profile);
+ }
+
+
+ @Override
+ public SoundCloudProfile getUserProfile() {
+ return restTemplate.getForObject(getApiResourceUrl(""), SoundCloudProfile.class);
+ }
+
+ @Override
+ public List<Track> getFavorites() {
+ return restTemplate.getForObject(getApiResourceUrl("/favorites"), TrackList.class);
+ }
+
+ @Override
+ public List<Track> getTracks() {
+ return restTemplate.getForObject(getApiResourceUrl("/tracks"), TrackList.class);
+ }
+
+
+
+}
@@ -0,0 +1,22 @@
+package org.springframework.social.soundcloud.api.impl;
+
+import org.springframework.social.soundcloud.api.MeOperations;
+import org.springframework.web.client.RestTemplate;
+
+public class MeTemplate extends AbstractUserTemplate implements MeOperations {
+
+ public MeTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser) {
+ super(restTemplate, isAuthorizedForUser);
+ }
+
+ @Override
+ protected String getUsersResourcePrefix() {
+ return "/me";
+ }
+
+
+
+
+
+
+}
@@ -0,0 +1,58 @@
+package org.springframework.social.soundcloud.api.impl;
+
+
+
+import org.springframework.social.soundcloud.api.ResolveOperations;
+import org.springframework.social.soundcloud.api.SoundCloudProfile;
+import org.springframework.social.soundcloud.api.Track;
+import org.springframework.web.client.RestTemplate;
+
+public class ResolveTemplate extends AbstractSoundCloudResourceOperations implements ResolveOperations {
+
+
+
+
+ public ResolveTemplate(RestTemplate restTemplate,
+ boolean isAuthorizedForUser) {
+ super(restTemplate, isAuthorizedForUser);
+ }
+
+ protected String getResolvableResourceBaseUrl()
+ {
+ return "http://soundcloud.com";
+ }
+
+ protected String getResolvableResourceUrl(String resourcePath)
+ {
+ return getResolvableResourceBaseUrl() + resourcePath;
+ }
+
+ @Override
+ protected String getApiResourceBaseUrl() {
+ return getApiBaseUrl() + "/resolve";
+ }
+
+ @Override
+ public <T> T resolveSoundCloudResource(String resourceUrl,Class<T> t)
+ {
+ return restTemplate.getForObject(getApiResourceUrl("?url=" + resourceUrl), t);
+ }
+
+ @Override
+ public SoundCloudProfile resolveUserProfile(String username)
+ {
+ return resolveSoundCloudResource(getResolvableResourceUrl("/" + username),SoundCloudProfile.class);
+ }
+
+ @Override
+ public Track resolveTrack(String trackUrl)
+ {
+ return resolveSoundCloudResource(trackUrl,Track.class);
+ }
+
+
+
+
+
+
+}
Oops, something went wrong. Retry.

0 comments on commit 5fc8e79

Please sign in to comment.