soundcloud-ruby-api-wrapper 0.1.3 → 0.1.5

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/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- begin
4
+ begin
5
5
  require 'jeweler'
6
+
7
+
6
8
  Jeweler::Tasks.new do |gem|
7
9
  gem.name = "ruby-api-wrapper"
8
10
  gem.summary = %Q{TODO}
@@ -11,12 +13,12 @@ begin
11
13
  gem.authors = ["Johannes Wagener"]
12
14
  gem.add_dependency "jwagener-oauth-active-resource"
13
15
  gem.add_dependency "oauth"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
+ end
16
17
  rescue LoadError
17
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
19
  end
19
20
 
21
+
20
22
  require 'spec/rake/spectask'
21
23
  Spec::Rake::SpecTask.new(:spec) do |spec|
22
24
  spec.libs << 'lib' << 'spec'
@@ -29,7 +31,6 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
31
  spec.rcov = true
30
32
  end
31
33
 
32
-
33
34
  task :default => :spec
34
35
 
35
36
  require 'rake/rdoctask'
@@ -46,4 +47,3 @@ Rake::RDocTask.new do |rdoc|
46
47
  rdoc.rdoc_files.include('README*')
47
48
  rdoc.rdoc_files.include('lib/**/*.rb')
48
49
  end
49
-
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 4
4
+ :patch: 5
data/lib/soundcloud.rb CHANGED
@@ -12,8 +12,11 @@ require 'oauth_active_resource'
12
12
 
13
13
  module Soundcloud
14
14
  # Will create an OAuth Consumer for you.
15
+ #
15
16
  # You have to register your application on soundcloud.com to get a consumer token and secret.
17
+ #
16
18
  # Optionally you can specify another provider site (i.e. http://api.sandbox-soundcloud.com)
19
+ #
17
20
  # Default provider site is http://api.soundcloud.com
18
21
  def self.consumer(consumer_token,consumer_secret, site = 'http://api.soundcloud.com')
19
22
  return OAuth::Consumer.new(consumer_token, consumer_secret, {
@@ -30,14 +33,15 @@ module Soundcloud
30
33
  # This module is bound to the given OAuth access token.
31
34
  #
32
35
  # Options:
33
- # :access_token = your_oauth_access token
34
- # :site = soundcloud_api_site (i.e. "http://api.sandbox-soundcloud.com", defaults to "http://api.soundcloud.com")
36
+ # :access_token = your oauth access token
37
+ # :site = soundcloud api site (i.e. "http://api.sandbox-soundcloud.com", defaults to "http://api.soundcloud.com")
35
38
  # Examples:
36
39
  #
40
+ # # unauthenticated to "http://api.soundcloud.com"
37
41
  # cl = Soundcloud.register()
38
- # => unauthenticated to "http://api.soundcloud.com"
42
+ #
43
+ # # authenticated connection to soundcloud sandbox
39
44
  # cl = Soundcloud.register({:access_token => your_access_token, :site => "http://api.sandbox-soundcloud.com"})
40
- # => authenticated connection to soundcloud sandbox
41
45
  #
42
46
  def self.register(options = {})
43
47
  options[:site] = options[:site] || 'http://api.soundcloud.com'
@@ -1,16 +1,40 @@
1
1
  module Soundcloud
2
- module Models
3
-
2
+ module Models
4
3
  # Soundcloud Comment resource
5
4
  #
5
+ # Look up the resource attributes and filtering usage here:
6
+ #
6
7
  # http://wiki.github.com/soundcloud/api/documentation#comment
7
8
  #
8
- # See Soundcloud::Models::Track
9
+ # Examples:
10
+ #
11
+ # # add a comment to a track
12
+ # some_track = sc_client.Track.find('some-track')
13
+ # sc_client.Comment.create({:track => some_track, :body => 'Nice Track!'})
14
+ #
15
+ # # optionally you can add a timestamp (in milliseconds)
16
+ # sc_client.Comment.create({:track => some_track, :body => 'nice drums!', :timestamp => 5000})
17
+ #
18
+ # # display all comments of some track
19
+ # some_track.comments.each do |comment|
20
+ # p "#{comment.user.full_name} wrote: #{comment.body}"
21
+ # end
22
+
9
23
  class Comment < Base
10
24
  cattr_accessor :element_name
11
25
  belongs_to :user, :track
12
26
  self.site = "#{self.site}/tracks/:track_id/"
13
- self.element_name = 'comment'
14
- end
27
+ self.element_name = 'comment'
28
+
29
+ def initialize(options)
30
+ if not options[:track].nil?
31
+ options[:track_id] = options[:track].id
32
+ options.delete(:track)
33
+ end
34
+ super(options)
35
+ end
36
+
37
+ end
38
+
15
39
  end
16
40
  end
@@ -3,15 +3,17 @@ module Soundcloud
3
3
 
4
4
  # Soundcloud Event resource
5
5
  #
6
+ # Look up the resource attributes and filtering usage here:
7
+ #
6
8
  # http://wiki.github.com/soundcloud/api/documentation#event
7
9
  #
8
10
  # Examples:
9
11
  #
10
- # client.Event.find(:all,:params => {:filter => 'drop'})
11
- # => get all dropbox events
12
+ # # find the last 50 (default soundcloud limit) dropbox events
13
+ # sc_client.Event.find(:all,:params => {:filter => 'drop'})
12
14
  #
13
- # client.Event.find(:all)
14
- # => get all events
15
+ # # find the last 50 (default soundcloud limit) events
16
+ # sc_client.Event.find(:all)
15
17
  #
16
18
  class Event < Base
17
19
  belongs_to :user, :track
@@ -2,9 +2,30 @@ module Soundcloud
2
2
  module Models
3
3
  # Soundcloud Playlist resource
4
4
  #
5
- # http://wiki.github.com/soundcloud/api/documentation#playlist
5
+ # Note: At the moment, you cant create or delete playlists via Soundcloud API
6
+ #
7
+ # Look up the resource attributes and filtering usage here:
6
8
  #
9
+ # http://wiki.github.com/soundcloud/api/documentation#playlist
10
+ #
7
11
  # Examples:
12
+ #
13
+ # # Find a Playlist and add a track to it
14
+ # playlist = sc_client.Playlist('my-playlist')
15
+ # track = sc_client.Track('my-track')
16
+ # playlist.tracks << track
17
+ # playlist.save
18
+ #
19
+ # # Allow a user to access this track
20
+ # some_user = sc_client.User.find('some-user')
21
+ # playlist.permissions << some_user
22
+ # playlist.permissions.save
23
+ #
24
+ # # Delete first song in playlist
25
+ # playlist.tracks.delete playlist.tracks.first
26
+ # playlist.save
27
+ #
28
+
8
29
  class Playlist < Base
9
30
  belongs_to :user
10
31
  has_many :permissions
@@ -3,16 +3,19 @@ module Soundcloud
3
3
 
4
4
  # Soundcloud Track resource
5
5
  #
6
+ # Look up the resource attributes and filtering usage here:
7
+ #
6
8
  # http://wiki.github.com/soundcloud/api/documentation#track
7
9
  #
8
10
  # Examples:
9
11
  #
10
- # some_user_tracks = client.Track.find(:all, :from => '/users/some_user/tracks')
11
- # => gets the tracks from some_user
12
+ # # gets the tracks from some_user
13
+ # some_user_tracks = sc_client.Track.find(:all, :from => '/users/some_user/tracks')
12
14
  #
15
+ # # gets the first song from some_user_tracks
13
16
  # first_song = some_user_tracks.first
14
- # => gets the first song from some_user_tracks
15
17
  #
18
+ # # prints all comments of first_song with username, timestamp (can be nil) and comment body
16
19
  # first_song.comments.each do |comment|
17
20
  # if comment.timestamp.nil?
18
21
  # timestamp = ""
@@ -21,26 +24,25 @@ module Soundcloud
21
24
  # end
22
25
  # p "#{comment.user.username} #{timestamp}: #{comment.body}"
23
26
  # end
24
- # => Prints all comments of first_song with username, timestamp and body
25
27
  #
26
28
  #
27
- # slow_tracks = client.Track.find(:all, :params => { "bpm[to]" => "100"} )
28
- # => Gets tracks with a BPM <= 100
29
+ # # gets tracks with a BPM <= 100
30
+ # slow_tracks = sc_client.Track.find(:all, :params => { "bpm[to]" => "100"} )
29
31
  #
30
- # new_track = client.Track.new
32
+ # # create a new Track on Soundcloud with some_sound_file.mp3 as asset data
33
+ # new_track = sc_client.Track.new
31
34
  # new_track.title = 'New Track'
32
35
  # new_track.sharing = 'private'
33
36
  # new_track.set_asset_data(File.new('some_sound_file.wav')
34
37
  # new_track.save
35
- # => Create a new Track on Soundcloud with some_sound_file.mp3 as asset data
36
38
  #
39
+ # # downloads the original soundfile. some_sound_file.wav and another_sound_file.wav should be equal
37
40
  # File.open('another_sound_file.wav', 'w') {|f| f.write( new_track.download ) }
38
- # => Downloads the original soundfile. some_sound_file.wav and another_sound_file.wav should be equal
39
41
  #
40
- # some_user = client.User.find('some_user')
42
+ # # gives some_user permission to access the new_track
43
+ # some_user = sc_client.User.find('some_user')
41
44
  # new_track.permissions << some_user
42
45
  # new_track.permissions.save
43
- # => Gives some_user permission to access the new_track
44
46
  #
45
47
  #
46
48
  #
@@ -3,28 +3,38 @@ module Soundcloud
3
3
 
4
4
  # Soundcloud User resource
5
5
  #
6
+ # Look up the resource attributes and filtering usage here:
7
+ #
6
8
  # http://wiki.github.com/soundcloud/api/documentation#user
7
9
  #
8
10
  # Examples:
9
- # user = client.User.find('userABC')
10
- # => gets the user with username userABC
11
- #
12
- # erics = client.User.find(:all, :params=> {:q => "eric"})
13
- # erics.each do |user|
11
+ # # gets the user with username userABC
12
+ # user = sc_client.User.find('userABC')
13
+ #
14
+ # # finds all users named joe and print their usernames
15
+ # joes = sc_client.User.find(:all, :params=> {:q => "joe"})
16
+ # joes.each do |user|
14
17
  # p user.username
15
18
  # end
16
- # => finds all users named eric and print their usernames
17
19
  #
18
- # me = client.User.find(:one, :from => '/me')
19
- # => gets the logged-in user
20
+ # # gets the logged-in user
21
+ # me = client.User.find_me
22
+ #
23
+ # # checks if the first user named joe is following the second user named joe
24
+ # joe1 = joes.first
25
+ # joe2 = joes[1]
26
+ # joe1.has_contact?(joe2)
27
+ #
28
+ # # makes the loggedin user following joe2
29
+ # joe2.add_contact!
20
30
  #
21
- # eric1 = erics.first
22
- # eric2 = erics[1]
23
- # eric1.has_contact?(eric2)
24
- # => checks if the first user named eric is following the second user named eric
25
31
  #
26
- # eric2.add_contact!
27
- # => makes the loggedin user following eric2
32
+ # # Display all tracks of a user
33
+ # user = sc_client.User.find('some-user')
34
+ # user.tracks.each do |track|
35
+ # p track.title
36
+ # end
37
+
28
38
 
29
39
  class User < Base
30
40
  has_many :tracks, :contacts, :comments, :favorites, :playlists
@@ -33,6 +43,11 @@ module Soundcloud
33
43
 
34
44
  cattr_accessor :element_name
35
45
  self.element_name = 'user'
46
+
47
+ # Convenience method to find the logged in user
48
+ def self.find_me
49
+ find(:one, :from => '/me')
50
+ end
36
51
  end
37
52
 
38
53
  class Permission < User #:nodoc:
@@ -9,7 +9,7 @@ describe 'Soundcloud::Models::Comment' do
9
9
  @track = @sc.Track.find('static-test-track')
10
10
  end
11
11
 
12
- it 'should be able to create and deleta a new comment for a track' do
12
+ it 'should be able to create and delete a new comment for a track' do
13
13
 
14
14
  old_count = @track.comments.count
15
15
  comment = @sc.Comment.create({:track_id => @track.id, :body => "new API Test comment"})
@@ -27,5 +27,9 @@ describe 'Soundcloud::Models::Comment' do
27
27
  comment.track.id.should_not be nil
28
28
  end
29
29
 
30
+ it 'should create a new comment and associate the track_id' do
31
+ comment = @sc.Comment.new({:track => @track})
32
+ comment.track_id.should be @track.id
33
+ end
30
34
 
31
35
  end
@@ -39,4 +39,5 @@ describe "Soundcloud" do
39
39
  sc.to_s.should match(/Soundcloud::.+/)
40
40
  lambda{ sc.User.find(:one, :from => "/me")}.should_not raise_error ActiveResource::UnauthorizedAccess
41
41
  end
42
+
42
43
  end
@@ -84,4 +84,5 @@ describe "Soundcloud::Models::Track" do
84
84
  # check against online attribute, to make sure the complete user is loaded, not the nested user
85
85
  @test_track_1.user.online.should_not be nil
86
86
  end
87
+
87
88
  end
@@ -48,6 +48,11 @@ describe "Soundcloud::Models::User" do
48
48
  @api_test_2.has_favorite?(track1.id).should be true
49
49
  @api_test_2.has_favorite?(track2).should be false
50
50
  end
51
+
52
+ it 'should find the logged in user' do
53
+ my_user = @sc.User.find_me
54
+ my_user.username.should_not be nil
55
+ end
51
56
 
52
57
  end
53
58
 
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.3
4
+ version: 0.1.5
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-22 00:00:00 -07:00
12
+ date: 2009-05-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency