Appending consumer_key param to all requests to public resources.
Removing Event model.
19. November 2009With version 0.4.2 we switched back to the mojodna oauth gem, since the bug was finally fixed. We also had to switch to gemcutter.org to host our gems, since github doesn't support gem building and hosting anymore. By doing that we renamed jwagener-oauth-active-resource to oauth-active-resource.
September 2009With the soundcloud-ruby-api-wrapper version 0.4.1 we switched from the official (mojodna) oauth gem to pelle oauth gem (0.3.6) because of an everlasting,unfixed bug in the official gem.
$ sudo gem install oauth-active-resource -s http://gemcutter.orgThen install the soundcloud api wrapper gem:
$ sudo gem install soundcloud-ruby-api-wrapper -s http://gemcutter.org
require 'rubygems' gem 'soundcloud-ruby-api-wrapper' require 'soundcloud' # Create an anonymous soundcloud client # if you prefer to work with sandbox-soundcloud.com, replace this with: # sc_client = Soundcloud.register({:site => "http://api.sandbox-soundcloud.com"}) sc_client = Soundcloud.register # Find the 10 hottest tracks hot_tracks = sc_client.Track.find(:all,:params => {:order => 'hotness', :limit => 10}) # and display their titles p '==the 10 hottest tracks==' hot_tracks.each do |track| p track.title endTo test authentication you can use this small app, which will dispay the name of the logged in user.
require 'rubygems' gem 'soundcloud-ruby-api-wrapper' require 'soundcloud' gem 'oauth' require 'oauth' # Create a Soundcloud OAuth consumer token object sc_consumer = Soundcloud.consumer('YOUR_APPLICATION_CONSUMER_TOKEN','YOUR_APPLICATION_CONSUMER_SECRET') # Create an OAuth access token object access_token = OAuth::AccessToken.new(sc_consumer, 'YOUR_OAUTH_ACCESS_TOKEN', 'YOUR_OAUTH_ACCESS_SECRET') # Create an authenticated Soundcloud client, based on the access token sc_client = Soundcloud.register({:access_token => access_token}) # Get the logged in user my_user = sc_client.User.find_me # Display his full name p "Hello, my name is #{my_user.full_name}"Find more examples in these pages: [[Model Events]], [[Model Users]], [[Model Tracks]], [[Model Playlists]], [[Model Comments]].
playlist.tracksWhen saving the original resource, the nested array will be saved as well.
playlist.tracks << some_track playlist.save
playlist.permissionsBut have to be saved explicitly:
playlist.permissions << some_user playlist.permissions.save playlist.saveA lot of these collections are partials, that means Soundcloud API will not return more than 50 items per request. For example the user famous_dj has 120 fans/followers. famous_dj.fans will only return 50 fans. To get all fans you have to do something like this:
fans = [] limit = 50 begin some_fans = famous_dj.fans({:offset => fans.length, :limit => limit}) fans += some_fans end while some_fans.length >= limitThe array fans now contains all fans/followers of famous_dj.
track.add_favorite!Remove:
track.remove_favorite!Check:
track.is_favorite? => true or falseThe same works with the contacts of the logged-in user:
another_user.add_contact! another_user.remove_contact! another_user.is_contact? => true or falseYou can also check if another users follows some user or has a specific favorite:
user.has_contact?(some_user) => true of false user.has_favorite?(some_track) => true or false