Class: SoundcloudPlus
- Inherits:
-
Soundcloud
- Object
- Soundcloud
- SoundcloudPlus
- 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
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#attach(resource, value = nil, options = {}) ⇒ SoundcloudPlus
Attaches resource and resource id path.
-
#fetch! ⇒ Hashie
(also: #get!)
Fetches resources from current path with current options.
-
#initialize(options = {}) ⇒ SoundcloudPlus
constructor
A new instance of SoundcloudPlus.
- #me ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
Call method on fetched results.
-
#resolve(path) ⇒ Object
Finds the soundcloud id for a soundcloud link or path.
-
#where(params = {}) ⇒ SoundcloudPlus
Add parameters to the query options.
Constructor Details
#initialize(options = {}) ⇒ SoundcloudPlus
Returns a new instance of SoundcloudPlus.
14 15 16 17 |
# File 'lib/soundcloud-plus.rb', line 14 def initialize(={}) super @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
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/soundcloud-plus.rb', line 8 def @options end |
#path ⇒ Object
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
85 86 87 88 89 90 91 92 |
# File 'lib/soundcloud-plus.rb', line 85 def attach(resource, value = nil, = {}) @path << "/#{resource}" @options.merge!() 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
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 |
#me ⇒ Object
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
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
71 72 73 74 |
# File 'lib/soundcloud-plus.rb', line 71 def where(params = {}) @options.merge!(params) self end |