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/sc_connection.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, SCConnection
Class Method Summary (collapse)
-
+ (Object) add_resolver_to_mod(mod)
Quick hack to add support api.soundcloud.com/resolve .
-
+ (Object) consumer(consumer_token, consumer_secret, site = @default_site)
Will create an OAuth Consumer for you.
-
+ (Object) register(options = {})
Will create a soundcloud module containing all the soundcloud models.
Class Method Details
+ (Object) add_resolver_to_mod(mod)
Quick hack to add support api.soundcloud.com/resolve . TODO jw cleanup :)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/soundcloud.rb', line 60 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("#{base.site}/resolve?url=#{url}", "Accept"=>"application/xml") if response.code == "302" uri = URI.parse(response.header['Location']) path = uri.path # Extract the secret token, if present if uri.query token = uri.query[/secret_token=(.{7})/, 1] params = {:secret_token => token} unless token.nil? end resource_class = base.new.send(:find_or_create_resource_for_collection, path.split('/')[-2]) resource_class.find(:one, :from => path, :params => params) else raise ActiveResource::ResourceNotFound.new(response) end end end mod end |
+ (Object) consumer(consumer_token, consumer_secret, site = @default_site)
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
26 27 28 29 30 31 32 33 |
# File 'lib/soundcloud.rb', line 26 def self.consumer(consumer_token,consumer_secret, site = @default_site) 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 |
+ (Object) register(options = {})
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"})
50 51 52 53 54 55 56 57 |
# File 'lib/soundcloud.rb', line 50 def self.register( = {}) [:site] = [:site] || @default_site 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 |