Getting started

Pages 7

Clone this wiki locally

Getting started

News

Adding support for key requirements, versioning, and linked partitions:

Consumer Key Requirement: a valid consumer key must be supplied, even when only accessing public resources

Versioning: requests to /v1 are now active.

Linked Partitioning: a request passed with linked_partitioning=1 will have a next-paritition-href field in the response body. This field will contain a link to the next partition of the request.

These features are currently only live on sandbox-soundcloud.

21. November 2009

Version 0.4.5 brings support for groups and the resolve api:

groups: read only support for groups and it’s tracks, members, moderators, contributors

resolver: Resolve almost any soundcloud permalink to an api resource. i.e.: sc_client.resolve(‘http://soundcloud.com/forss/flickermood’) will return the track object of the specified url.

Detailed documentation will follow.

19. November 2009

With 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.

Sub-resources

Nested sub-resources

These are directly embedded in the resource. For example a playlist has a track array.

playlist.tracks

When saving the original resource, the nested array will be saved as well.

playlist.tracks &lt;&lt; some_track
playlist.save

Separate sub-resources

These are separated from the original resource.
Example:
A Track has the path “/tracks/[TRACK ID]”
This track has a collection of users, which have access to this track, called permissions.
These can be accessed via the path “/tracks/[TRACK ID]/permission”.

A 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:

Linked Partitioning

Linked partitioning can be used to get N resources, then then next N, then then next N, and so on. At the moment, it is only live on sandbox-soundcloud.com, and is opt-in. Set linked_partitioning to 1 to activate it. The response will then have a next-partition-href field, and a get_next_partition() method. For example:

# Connect to SoundCloud
soundcloud = Soundcloud.register({:consumer_key => 'Your_Consumer_Key', :site => 'http://api.sandbox-soundcloud.com'})
# This will request the 10 hottest tracks, with linked partitioning on.
hot_tracks = soundcloud.Track.find(:all, :params => {:limit => 10, :linked_partitioning => 1})
# This will print the title of each track: the return object acts as Array
hot_tracks.each do |track|
p track.title
end
# To get the next partition of tracks:
hot_tracks2 = hot_tracks.get_next_partition(soundcloud.Track)
hot_tracks2.each do |track|
p track.title
end
# To loop over all tracks, in sets of 10:
while hot_tracks != nil
hot_tracks.each do |track|
p track.title
end
hot_tracks = hot_tracks.get_next_partition(soundcloud.Track)
end

Note that get_next_partition will return nil if there are no more resources to get. Note also that you must pass the soundcloud object and the desired method to get_next_partition. A request for Users would thus look like: get_next_partition(soundcloud.User)