Class: SoundcloudPlus

Inherits:
Soundcloud
  • Object
show all
Defined in:
lib/soundcloud-plus.rb

Constant Summary collapse

PLURAL_CALLS =
%w(user track playlist group comment connection activity app following follower favorite favoriter email)
SINGULAR_CALLS =
%w(shared-to secret-token all own affiliated exclusive)
PARAMETERS =
%w(limit order)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SoundcloudPlus

Returns a new instance of SoundcloudPlus.



14
15
16
17
# File 'lib/soundcloud-plus.rb', line 14

def initialize(options={})
   super options
   @path = ""
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Call method on fetched results



20
21
22
23
# File 'lib/soundcloud-plus.rb', line 20

def method_missing(method, *args, &block)
   @results ||= self.fetch!
   @results.send(method)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/soundcloud-plus.rb', line 8

def options
  @options
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/soundcloud-plus.rb', line 8

def path
  @path
end

Instance Method Details

#attach(resource, value = nil, options = {}) ⇒ SoundcloudPlus

Attaches resource and resource id path

Examples:

Attach user resource to path

client = SoundcloudPlus.new(:client_id => "client_id")
client.attach("users", "bob")
client.path  # => /users/1234

Returns:



85
86
87
88
89
90
91
92
# File 'lib/soundcloud-plus.rb', line 85

def attach(resource, value = nil, options = {})
   @path << "/#{resource}"
   @options.merge!(options)
   if value
      @path << (value.class == Fixnum ? "/#{value}" : "/#{resolve(value).id}" )
   end
   self
end

#fetch!Hashie Also known as: get!

Fetches resources from current path with current options

Examples:

Fetching user

client = SoundcloudPlus.new(:client_id => "client_id")
user = client.user(1234).fetch!
user.permalink # => "bob"

Returns:

  • (Hashie)

    Hashie containing resource from path



103
104
105
106
107
108
109
# File 'lib/soundcloud-plus.rb', line 103

def fetch!
   old_path = path
   if old_path && path.length > 0
      path = ""
      @results = get(old_path, @options)
   end
end

#meObject



25
26
27
# File 'lib/soundcloud-plus.rb', line 25

def me
   @path = "/me"
end

#resolve(path) ⇒ Object

Finds the soundcloud id for a soundcloud link or path

Examples:

Getting id of song with link

client = SoundcloudPlus.new(:client_id => "client_id")
track = client.resolve("http://soundcloud.com/poopyman/poopy-pants-song") 
track.name # => "Poopy Pants Song"

Getting id of song with



121
122
123
124
125
# File 'lib/soundcloud-plus.rb', line 121

def resolve(path)
   path = URI.parse(path).path.sub(/\A\/+/,'')
   url = "http://#{site}/#{path}"
   @results = get("/resolve", :url => url)
end

#where(params = {}) ⇒ SoundcloudPlus

Add parameters to the query options

Examples:

Adding limit to number of user returned

client = SoundcloudPlus.new(:client_id => "client_id")
client.user.where(:limit => 5)

Returns:



71
72
73
74
# File 'lib/soundcloud-plus.rb', line 71

def where(params = {})
   @options.merge!(params)
   self
end