Class: Lastfm::MethodCategory::Base
- Inherits:
-
Object
- Object
- Lastfm::MethodCategory::Base
show all
- Defined in:
- lib/lastfm/method_category/base.rb
Direct Known Subclasses
Album, Artist, Auth, Chart, Event, Geo, Library, Radio, Tag, Tasteometer, Track, User
Class Method Summary
collapse
-
.__define_method(method, id, mandatory, optional, &block) ⇒ Object
-
.method_for_authentication(id, mandatory, optional = [], &block) ⇒ Object
-
.method_for_secure_authentication(id, mandatory, optional = [], &block) ⇒ Object
-
.method_with_authentication(id, mandatory, optional = [], &block) ⇒ Object
-
.regular_method(id, mandatory, optional = [], &block) ⇒ Object
-
.write_method(id, mandatory, optional = []) ⇒ Object
Instance Method Summary
collapse
Constructor Details
#initialize(lastfm) ⇒ Base
Returns a new instance of Base.
38
39
40
|
# File 'lib/lastfm/method_category/base.rb', line 38
def initialize(lastfm)
@lastfm = lastfm
end
|
Class Method Details
.__define_method(method, id, mandatory, optional, &block) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/lastfm/method_category/base.rb', line 27
def __define_method(method, id, mandatory, optional, &block)
unless block
block = Proc.new { |response| response.xml }
end
define_method(id) do |*args|
block.call(send(method, id.to_s.camelize(:lower), Lastfm::Util.build_options(args, mandatory, optional)))
end
end
|
.method_for_authentication(id, mandatory, optional = [], &block) ⇒ Object
15
16
17
|
# File 'lib/lastfm/method_category/base.rb', line 15
def method_for_authentication(id, mandatory, optional = [], &block)
__define_method(:request_for_authentication, id, mandatory, optional, &block)
end
|
.method_for_secure_authentication(id, mandatory, optional = [], &block) ⇒ Object
19
20
21
|
# File 'lib/lastfm/method_category/base.rb', line 19
def method_for_secure_authentication(id, mandatory, optional = [], &block)
__define_method(:request_for_secure_authentication, id, mandatory, optional, &block)
end
|
.method_with_authentication(id, mandatory, optional = [], &block) ⇒ Object
11
12
13
|
# File 'lib/lastfm/method_category/base.rb', line 11
def method_with_authentication(id, mandatory, optional = [], &block)
__define_method(:request_with_authentication, id, mandatory, optional, &block)
end
|
.regular_method(id, mandatory, optional = [], &block) ⇒ Object
23
24
25
|
# File 'lib/lastfm/method_category/base.rb', line 23
def regular_method(id, mandatory, optional = [], &block)
__define_method(:request, id, mandatory, optional, &block)
end
|
.write_method(id, mandatory, optional = []) ⇒ Object
5
6
7
8
9
|
# File 'lib/lastfm/method_category/base.rb', line 5
def write_method(id, mandatory, optional = [])
__define_method(:write_request, id, mandatory, optional) do |response|
response.success?
end
end
|
Instance Method Details
#request(*args) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/lastfm/method_category/base.rb', line 58
def request(*args)
method, *rest = args
method = [self.class.name.split(/::/).last.downcase, method].join('.')
@lastfm.request(method, *rest)
end
|
#request_for_authentication(method, params = {}) ⇒ Object
50
51
52
|
# File 'lib/lastfm/method_category/base.rb', line 50
def request_for_authentication(method, params = {})
request(method, params, :get, true)
end
|
#request_for_secure_authentication(method, params = {}) ⇒ Object
54
55
56
|
# File 'lib/lastfm/method_category/base.rb', line 54
def request_for_secure_authentication(method, params = {})
request(method, params, :post, true, false, true)
end
|
#request_with_authentication(method, params = {}) ⇒ Object
46
47
48
|
# File 'lib/lastfm/method_category/base.rb', line 46
def request_with_authentication(method, params = {})
request(method, params, :get, true, true)
end
|
#write_request(method, params = {}) ⇒ Object
42
43
44
|
# File 'lib/lastfm/method_category/base.rb', line 42
def write_request(method, params = {})
request(method, params, :post, true, true)
end
|