soundcloud-ruby-api-wrapper 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.html +10 -10
- data/VERSION.yml +1 -1
- data/lib/soundcloud/models/comment.rb +15 -4
- data/lib/soundcloud/models/event.rb +16 -4
- data/lib/soundcloud/models/playlist.rb +21 -1
- data/lib/soundcloud/models/track.rb +54 -11
- data/lib/soundcloud/models/user.rb +36 -2
- data/spec/soundcloud_event_spec.rb +5 -0
- data/spec/soundcloud_track_spec.rb +7 -7
- metadata +2 -2
data/README.html
CHANGED
@@ -29,7 +29,7 @@ Look at <a href="http://wiki.github.com/soundcloud/api/oauth-example">http://wik
|
|
29
29
|
|
30
30
|
<h3>First steps</h3>
|
31
31
|
|
32
|
-
Let's start with a simple app
|
32
|
+
Let's start with a simple app. It will find and display the 10 hottest tracks of alltime. You don't need any OAuth authentication to do this.
|
33
33
|
|
34
34
|
<pre>
|
35
35
|
require 'rubygems'
|
@@ -42,7 +42,7 @@ require 'soundcloud'
|
|
42
42
|
sc_client = Soundcloud.register
|
43
43
|
|
44
44
|
# Find the 10 hottest tracks
|
45
|
-
hot_tracks = sc_client.Track.find(:all,:params => {:order => '
|
45
|
+
hot_tracks = sc_client.Track.find(:all,:params => {:order => 'hotness', :limit => 10})
|
46
46
|
|
47
47
|
# and display their titles
|
48
48
|
p '==the 10 hottest tracks=='
|
@@ -69,7 +69,7 @@ sc_consumer = Soundcloud.consumer('YOUR_APPLICATION_CONSUMER_TOKEN','YOUR_APPLIC
|
|
69
69
|
access_token = OAuth::AccessToken.new(sc_consumer, 'YOUR_OAUTH_ACCESS_TOKEN', 'YOUR_OAUTH_ACCESS_SECRET')
|
70
70
|
|
71
71
|
# Create an authenticated Soundcloud client, based on the access token
|
72
|
-
sc_client = Soundcloud.register({
|
72
|
+
sc_client = Soundcloud.register({:access_token => access_token})
|
73
73
|
|
74
74
|
# Get the logged in user
|
75
75
|
my_user = sc_client.User.find_me
|
@@ -79,25 +79,25 @@ p "Hello, my name is #{my_user.full_name}"
|
|
79
79
|
|
80
80
|
</pre>
|
81
81
|
|
82
|
-
Find more examples in
|
82
|
+
Find more examples in these pages: [[Model Events]], [[Model Users]], [[Model Tracks]], [[Model Playlists]], [[Model Comments]].
|
83
83
|
|
84
84
|
|
85
85
|
<h2>Sub-resources</h2>
|
86
86
|
|
87
87
|
The Soundcloud API provides 3 different types of sub-resources:
|
88
|
-
<h3>Nested</h3>
|
88
|
+
<h3>Nested sub-resources</h3>
|
89
89
|
|
90
|
-
These are directly embedded in the
|
90
|
+
These are directly embedded in the resource. For example a playlist has a track array.
|
91
91
|
|
92
92
|
<pre>playlist.tracks</pre>
|
93
93
|
|
94
94
|
When saving the original resource, the nested array will be saved as well.
|
95
95
|
|
96
|
-
<pre>playlist.tracks
|
96
|
+
<pre>playlist.tracks << some_track
|
97
97
|
playlist.save
|
98
98
|
</pre>
|
99
99
|
|
100
|
-
<h3>Separate</h3>
|
100
|
+
<h3>Separate sub-resources</h3>
|
101
101
|
|
102
102
|
These are separated from the original resource.
|
103
103
|
Example:
|
@@ -111,7 +111,7 @@ In ruby they are accessed like nested resources:
|
|
111
111
|
|
112
112
|
But have to be saved explicitly:
|
113
113
|
<pre>
|
114
|
-
playlist.permissions
|
114
|
+
playlist.permissions << some_user
|
115
115
|
playlist.permissions.save
|
116
116
|
playlist.save</pre>
|
117
117
|
|
@@ -130,7 +130,7 @@ end while some_fans.count >= limit
|
|
130
130
|
The array fans now contains all fans/followers of famous_dj.
|
131
131
|
|
132
132
|
|
133
|
-
<h3>'Single changeable' separate</h3>
|
133
|
+
<h3>'Single changeable' separate sub-resources</h3>
|
134
134
|
|
135
135
|
Some separate collections can't be saved in a bulk request. Instead each item has to be added or removed explicitly.
|
136
136
|
For now this only affects the contacts (followees) and favorites of a user.
|
data/VERSION.yml
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
module Soundcloud
|
2
|
-
module Models
|
3
|
-
#
|
2
|
+
module Models
|
3
|
+
#
|
4
|
+
# SC API Attributes (as of 26/05/09):
|
5
|
+
# * body
|
6
|
+
# * timestamp
|
7
|
+
# * id
|
8
|
+
# * track_id
|
9
|
+
# * user_id
|
10
|
+
# * uri
|
11
|
+
#
|
12
|
+
# Custom Wrapper Attributes/Methods:
|
13
|
+
# * user
|
14
|
+
# * track
|
4
15
|
#
|
5
16
|
# Look up the resource attributes and filtering usage here:
|
6
|
-
#
|
17
|
+
#
|
7
18
|
# http://wiki.github.com/soundcloud/api/documentation#comment
|
8
19
|
#
|
9
20
|
# Examples:
|
@@ -13,7 +24,7 @@ module Soundcloud
|
|
13
24
|
# sc_client.Comment.create({:track => some_track, :body => 'Nice Track!'})
|
14
25
|
#
|
15
26
|
# # optionally you can add a timestamp (in milliseconds)
|
16
|
-
# sc_client.Comment.create({:track => some_track, :body => 'nice drums!', :timestamp => 5000})
|
27
|
+
# sc_client.Comment.create({:track => some_track, :body => 'nice drums @ the 5th second!', :timestamp => 5000})
|
17
28
|
#
|
18
29
|
# # display all comments of some track
|
19
30
|
# some_track.comments.each do |comment|
|
@@ -1,19 +1,31 @@
|
|
1
1
|
module Soundcloud
|
2
2
|
module Models
|
3
|
-
# Look up the resource attributes and filtering usage here:
|
4
3
|
#
|
4
|
+
# SC API Attributes (as of 26/05/09):
|
5
|
+
# * type
|
6
|
+
# * id
|
7
|
+
# * created_at
|
8
|
+
# * resource_id
|
9
|
+
# * comment/track/user (embedded resource, depending on type)
|
10
|
+
#
|
11
|
+
# Look up the resource attributes and filtering usage here:
|
12
|
+
#
|
5
13
|
# http://wiki.github.com/soundcloud/api/documentation#event
|
6
14
|
#
|
7
15
|
# Examples:
|
8
16
|
#
|
9
|
-
# # find the last 50 (default soundcloud limit) dropbox events
|
10
|
-
# sc_client.Event.find(:all,:params => {:filter => 'drop'})
|
17
|
+
# # find the last 50 (default soundcloud limit) dropbox events and display the titles of the dropped tracks
|
18
|
+
# dropbox_events = sc_client.Event.find(:all,:params => {:filter => 'drop'})
|
19
|
+
#
|
20
|
+
# dropbox_events.each do |event|
|
21
|
+
# p event.track.title
|
22
|
+
# end
|
11
23
|
#
|
12
24
|
# # find the last 50 (default soundcloud limit) events
|
13
25
|
# sc_client.Event.find(:all)
|
14
26
|
#
|
15
27
|
class Event < Base
|
16
|
-
belongs_to :user, :track
|
28
|
+
#belongs_to :user, :track, :comment # this is not right
|
17
29
|
cattr_accessor :element_name
|
18
30
|
self.element_name = 'event'
|
19
31
|
end
|
@@ -2,8 +2,28 @@ module Soundcloud
|
|
2
2
|
module Models
|
3
3
|
# Note: At the moment, you can't create or delete playlists via Soundcloud API
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# SC API Attributes (as of 26/05/09):
|
6
|
+
# * created_at
|
7
|
+
# * description
|
8
|
+
# * genre
|
9
|
+
# * id
|
10
|
+
# * permalink
|
11
|
+
# * title
|
12
|
+
# * user_id
|
13
|
+
# * permalink_url
|
14
|
+
# * uri
|
15
|
+
# * artwork_url
|
16
|
+
# * duration
|
17
|
+
# * type
|
18
|
+
# * user (overwritten by wrapper)
|
19
|
+
# * tracks (array)
|
6
20
|
#
|
21
|
+
# Custom Wrapper Attributes/Methods:
|
22
|
+
# * user
|
23
|
+
# * permissions
|
24
|
+
#
|
25
|
+
# Look up the resource attributes and filtering usage here:
|
26
|
+
#
|
7
27
|
# http://wiki.github.com/soundcloud/api/documentation#playlist
|
8
28
|
#
|
9
29
|
# Examples:
|
@@ -1,7 +1,43 @@
|
|
1
1
|
module Soundcloud
|
2
2
|
module Models
|
3
3
|
# Look up the resource attributes and filtering usage here:
|
4
|
-
#
|
4
|
+
#
|
5
|
+
# SC API Attributes (as of 26/05/09):
|
6
|
+
# * id
|
7
|
+
# * user_id
|
8
|
+
# * permalink
|
9
|
+
# * description
|
10
|
+
# * sharing
|
11
|
+
# * bpm
|
12
|
+
# * comments_count
|
13
|
+
# * created_at
|
14
|
+
# * downloadable
|
15
|
+
# * downloads_count
|
16
|
+
# * duration
|
17
|
+
# * genre
|
18
|
+
# * streamable
|
19
|
+
# * uri
|
20
|
+
# * user (overwritten by wrapper)
|
21
|
+
# * permalink_url
|
22
|
+
# * playback_count
|
23
|
+
# * artwork_url
|
24
|
+
# * waveform_url
|
25
|
+
# * purchase_url
|
26
|
+
# * stream_url
|
27
|
+
# * user_playback_count
|
28
|
+
# * user_favorite
|
29
|
+
#
|
30
|
+
# Custom Wrapper Attributes/Methods:
|
31
|
+
# * user
|
32
|
+
# * permissions
|
33
|
+
# * comments
|
34
|
+
# * is_favorite?
|
35
|
+
# * add_favorite!
|
36
|
+
# * remove_favorite!
|
37
|
+
# * asset_data (= File.new('/your file..'))
|
38
|
+
#
|
39
|
+
# Look up the resource attributes and filtering usage here:
|
40
|
+
#
|
5
41
|
# http://wiki.github.com/soundcloud/api/documentation#track
|
6
42
|
#
|
7
43
|
# Examples:
|
@@ -9,7 +45,7 @@ module Soundcloud
|
|
9
45
|
# # gets 50 (Soundcloud API limit) tracks from some_user
|
10
46
|
# some_user_tracks = some_user.tracks
|
11
47
|
#
|
12
|
-
# # gets the
|
48
|
+
# # gets the latest song from some_user_tracks
|
13
49
|
# first_song = some_user_tracks.first
|
14
50
|
#
|
15
51
|
# # prints 50 (Soundcloud API limit) comments of first_song with username, timestamp (can be nil) and comment body
|
@@ -31,11 +67,12 @@ module Soundcloud
|
|
31
67
|
# new_track = sc_client.Track.new
|
32
68
|
# new_track.title = 'New Track'
|
33
69
|
# new_track.sharing = 'private'
|
34
|
-
# new_track.
|
70
|
+
# new_track.asset_data = File.new('some_sound_file.wav')
|
35
71
|
# new_track.save
|
36
72
|
#
|
37
|
-
# # downloads the original soundfile.
|
38
|
-
#
|
73
|
+
# # downloads the original soundfile.
|
74
|
+
# #some_sound_file.wav and downloaded_file should be the same (the open call requires the 'open-uri' gem)
|
75
|
+
# downloaded_file = open new_track.download_url
|
39
76
|
#
|
40
77
|
# # gives some_user permission to access the new_track
|
41
78
|
# some_user = sc_client.User.find('some_user')
|
@@ -52,16 +89,22 @@ module Soundcloud
|
|
52
89
|
can_be_a_single_changeable :favorite
|
53
90
|
|
54
91
|
cattr_accessor :element_name
|
92
|
+
attr_accessor :asset_data
|
55
93
|
self.element_name = 'track'
|
56
94
|
|
57
|
-
def
|
95
|
+
def download_url
|
58
96
|
raise Exception.new('Track is not downloadable') if not downloadable
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
97
|
+
original_download_url = super
|
98
|
+
if sharing == "private"
|
99
|
+
begin
|
100
|
+
response = connection.handle_response( self.class.oauth_connection.get( original_download_url ) )
|
101
|
+
return original_download_url
|
102
|
+
rescue ActiveResource::Redirection => redirection
|
103
|
+
return redirection.response['Location']
|
104
|
+
end
|
105
|
+
else
|
106
|
+
return original_download_url
|
63
107
|
end
|
64
|
-
return response
|
65
108
|
end
|
66
109
|
|
67
110
|
# multipart stuff, to upload a soundfile
|
@@ -1,10 +1,46 @@
|
|
1
1
|
module Soundcloud
|
2
2
|
module Models
|
3
|
+
# SC API Attributes (as of 26/05/09):
|
4
|
+
# * id
|
5
|
+
# * username
|
6
|
+
# * full_name
|
7
|
+
# * description
|
8
|
+
# * city
|
9
|
+
# * country
|
10
|
+
# * discogs_name
|
11
|
+
# * myspace_name
|
12
|
+
# * website
|
13
|
+
# * website_title
|
14
|
+
# * online
|
15
|
+
# * avatar_url
|
16
|
+
# * permalink_url
|
17
|
+
# * uri
|
18
|
+
# * track_count
|
19
|
+
#
|
20
|
+
# Custom Wrapper Attributes/Methods:
|
21
|
+
# * tracks
|
22
|
+
# * contacts
|
23
|
+
# * comments
|
24
|
+
# * favorites
|
25
|
+
# * playlists
|
26
|
+
# * fans
|
27
|
+
# * is_contact?
|
28
|
+
# * add_contact!
|
29
|
+
# * remove_contact!
|
30
|
+
# * has_favorite?(track/track_id)
|
31
|
+
# * has_contact?(user/user_id)
|
32
|
+
#
|
3
33
|
# Look up the resource attributes and filtering usage here:
|
4
34
|
#
|
5
35
|
# http://wiki.github.com/soundcloud/api/documentation#user
|
6
36
|
#
|
37
|
+
# Custom Wrapper Class Methods
|
38
|
+
# * find_me
|
39
|
+
#
|
7
40
|
# Examples:
|
41
|
+
# # gets the logged-in user
|
42
|
+
# me = client.User.find_me
|
43
|
+
#
|
8
44
|
# # gets the user with username userABC
|
9
45
|
# user = sc_client.User.find('userABC')
|
10
46
|
#
|
@@ -14,8 +50,6 @@ module Soundcloud
|
|
14
50
|
# p user.username
|
15
51
|
# end
|
16
52
|
#
|
17
|
-
# # gets the logged-in user
|
18
|
-
# me = client.User.find_me
|
19
53
|
#
|
20
54
|
# # checks if the first user named joe is following the second user named joe
|
21
55
|
# joe1 = joes.first
|
@@ -11,4 +11,9 @@ describe 'Soundcloud::Models::Event' do
|
|
11
11
|
it 'should get the last events' do
|
12
12
|
events = @sc.Event.find(:all)
|
13
13
|
end
|
14
|
+
|
15
|
+
it 'should get a fan event and should provide the user resource' do
|
16
|
+
fan_events = @sc.Event.find(:all,:params => {:type => 'Fan'})
|
17
|
+
fan_events.first.user.username.should_not be nil
|
18
|
+
end
|
14
19
|
end
|
@@ -31,7 +31,8 @@ describe "Soundcloud::Models::Track" do
|
|
31
31
|
track = @sc.Track.new
|
32
32
|
track.title = 'API Test 1'
|
33
33
|
track.sharing = 'private'
|
34
|
-
track.set_asset_data(test_track_file)
|
34
|
+
# track.set_asset_data(test_track_file)
|
35
|
+
track.asset_data = test_track_file
|
35
36
|
track.save
|
36
37
|
|
37
38
|
track.destroy
|
@@ -63,16 +64,15 @@ describe "Soundcloud::Models::Track" do
|
|
63
64
|
@test_track_1.is_favorite?.should be false
|
64
65
|
end
|
65
66
|
|
66
|
-
it 'should be able to download a track' do
|
67
|
-
track = @sc.Track.find(:one, :from => '/users/api-test-2/tracks/
|
68
|
-
track.
|
67
|
+
it 'should be able to download a private track' do
|
68
|
+
track = @sc.Track.find(:one, :from => '/users/api-test-2/tracks/track3-1')
|
69
|
+
track.download_url
|
69
70
|
end
|
70
71
|
|
71
|
-
it 'should be able to download a track (unauthenticated)' do
|
72
|
+
it 'should be able to download a public track (unauthenticated)' do
|
72
73
|
usc = Soundcloud.register({:site => soundcloud_site})
|
73
74
|
track = usc.Track.find(:one, :from => '/users/api-test-2/tracks/track1-2')
|
74
|
-
|
75
|
-
track.download
|
75
|
+
track.download_url
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'should find tracks with a bpm <= 90' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundcloud-ruby-api-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Wagener
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|