Module: Soundcloud
- Defined in:
- lib/soundcloud.rb,
lib/soundcloud/models/base.rb,
lib/soundcloud/models/user.rb,
lib/soundcloud/models/group.rb,
lib/soundcloud/models/track.rb,
lib/soundcloud/models/comment.rb,
lib/soundcloud/models/playlist.rb,
lib/soundcloud/public_oauth_access_token.rb
Defined Under Namespace
Modules: Models Classes: PublicOAuthAccessToken
Class Method Summary collapse
-
.add_resolver_to_mod(mod) ⇒ Object
Quick hack to add support api.soundcloud.com/resolve .
-
.consumer(consumer_token, consumer_secret, site = 'http://api.soundcloud.com') ⇒ Object
Will create an OAuth Consumer for you.
-
.register(options = {}) ⇒ Object
Will create a soundcloud module containing all the soundcloud models.
Class Method Details
.add_resolver_to_mod(mod) ⇒ Object
Quick hack to add support api.soundcloud.com/resolve . TODO jw cleanup :)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/soundcloud.rb', line 56 def self.add_resolver_to_mod(mod) mod.module_eval do def self.resolve(url) base = self.const_get('Base') response = base.oauth_connection.get("/resolve?url=#{url}") if response.code == "302" path = URI.parse(response.header['Location']).path resource_class = base.new.send(:find_or_create_resource_for_collection, path.split('/')[-2]) resource_class.find(:one, :from => path) else raise ActiveResource::ResourceNotFound.new(response) end end end mod end |
.consumer(consumer_token, consumer_secret, site = 'http://api.soundcloud.com') ⇒ Object
Will create an OAuth Consumer for you.
You have to register your application on soundcloud.com to get a consumer token and secret.
Optionally you can specify another provider site (i.e. api.sandbox-soundcloud.com)
Default provider site is api.soundcloud.com
22 23 24 25 26 27 28 29 |
# File 'lib/soundcloud.rb', line 22 def self.consumer(consumer_token,consumer_secret, site = 'http://api.soundcloud.com') return OAuth::Consumer.new(consumer_token, consumer_secret, { :site => site, :request_token_path => "/oauth/request_token", :access_token_path => "/oauth/access_token", :authorize_path => "/oauth/authorize" }) end |
.register(options = {}) ⇒ Object
Will create a soundcloud module containing all the soundcloud models. This module is bound to the given OAuth access token.
Options:
:access_token = your oauth access token
:site = soundcloud api site (i.e. "http://api.sandbox-soundcloud.com", defaults to "http://api.soundcloud.com")
Examples:
# unauthenticated to "http://api.soundcloud.com"
cl = Soundcloud.register()
# authenticated connection to soundcloud sandbox
cl = Soundcloud.register({:access_token => your_access_token, :site => "http://api.sandbox-soundcloud.com"})
46 47 48 49 50 51 52 53 |
# File 'lib/soundcloud.rb', line 46 def self.register( = {}) [:site] = [:site] || 'http://api.soundcloud.com' if [:consumer_key].nil? && [:access_token].nil? raise "Error: No consumer key or OAuth access token supplied." end mod = SCOAuthActiveResource.register(self.ancestors.first, self.ancestors.first.const_get('Models'),) add_resolver_to_mod(mod) end |