Git Product home page Git Product logo

spring-social-soundcloud's Introduction

SoundCloud API Java Client and plugin for the Spring Social Framework ( http://www.springsource.org/spring-social )

Use Cases:

To make calls to the SoundCloud Api on behalf of a user (for example favoriting a track), the SoundCloud user must
give their permission to your application.  

The authentication dance required (where the user is directed to a permission dialog on SoundCloud and then redirected 
back to your application) is handled perfectly by the Spring Social framework.  

To use this functionality, create a Spring Social-enabled webapp and simply register the SoundCloudConnectionFactory
with the ConnectionFactoryRegistry, eg:

@Bean
@Scope(value="singleton", proxyMode=ScopedProxyMode.INTERFACES) 
public ConnectionFactoryLocator connectionFactoryLocator() {
	ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();

		registry.addConnectionFactory(new SoundCloudConnectionFactory(
		environment.getProperty("soundCloud.consumerKey"),
		environment.getProperty("soundCloud.consumerSecret")));
		return registry;
}

Once the user has given permission to your Spring Social webapp to use their SoundCloud account ( see 
http://www.springsource.org/spring-social for more details ), an authenticated API client can be obtained from the
user's connection:

  	Connection<SoundCloud> soundcloudConnection = 
		connectionRepository.findPrimaryConnection(SoundCloud.class);

    	SoundCloud authenticatedSoundCloudApi = soundcloud.getApi();
    
  	Page<Track> tracks = 
	authenticatedSoundCloudApi.tracksOperations().search("monsieur adi dancing with the dj");
    
    	Track firstResult = tracks.getNumberOfElements() > 0 ? tracks.getContent().get(0) : null;
    
    	if (firstResult != null) {
        
	authenticatedSoundCloudApi.meOperations().favoriteTrack(firstResult.getId());
    	
	}

As mentioned above the Spring Social framework here is managing the authentication dance - behind the scenes Spring
Social has obtained a SoundCloud session key which is linked to the user's authorisation.  Outside of a Spring-Social
enabled webapp, the authenticated API client could be constructed as follows.

    	SoundCloud authenticatedSoundCloudApi = new SoundCloudTemplate("myApiKey","mySessionKey");

To make unauthenticated calls (ie. those which do not require an end user's permission) - for example searching for
tracks or viewing a user's favorites, this module can be used standalone outside of a Spring-Social-enabled webapp.

To use the API in this way, simply create a new SoundCloudTemplate instance, passing in your applications API key:

    	SoundCloud unauthenticatedSoundCloudApi = new SoundCloudTemplate("myApiKey");

    	Page<Track> tracks = unauthenticatedSoundCloudApi.usersOperations().userOperations("mattslip").getFavorites();

Usage:

To use this module, either checkout the project, build and install locally ("mvn install" from the base directory of
your checkout) or add the following repository to your project's pom:

<repositories>
     <repository>
        <id>opensourceagility-snapshots</id>
        <url>http://repo.opensourceagility.com/snapshots</url>
    </repository>
</repositories>

Then simply add the following dependency to your project's pom:

      <dependency>
         <groupId>org.springframework.social</groupId>
         <artifactId>spring-social-soundcloud</artifactId>
         <version>1.0.1-SNAPSHOT</version>
     </dependency>


    

spring-social-soundcloud's People

Contributors

michaellavelle avatar nirre7 avatar sdouglass avatar

Watchers

Vitaliy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.