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, Group, Library, Radio, Tag, Tasteometer, Track, User
Class Method Summary
collapse
-
.__define_method(method, id, params, &block) ⇒ Object
-
.any_params(*args) ⇒ Object
-
.method_for_authentication(id, params = {}, &block) ⇒ Object
-
.method_for_secure_authentication(id, params = {}, &block) ⇒ Object
-
.method_with_authentication(id, params = {}, &block) ⇒ Object
-
.regular_method(id, params = {}, &block) ⇒ Object
-
.write_method(id, params = {}) ⇒ Object
Instance Method Summary
collapse
Constructor Details
#initialize(lastfm) ⇒ Base
Returns a new instance of Base.
60
61
62
|
# File 'lib/lastfm/method_category/base.rb', line 60
def initialize(lastfm)
@lastfm = lastfm
end
|
Class Method Details
.__define_method(method, id, params, &block) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/lastfm/method_category/base.rb', line 39
def __define_method(method, id, params, &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,
params[:required],
params[:optional]
)
)
)
end
end
|
.any_params(*args) ⇒ Object
13
14
15
|
# File 'lib/lastfm/method_category/base.rb', line 13
def any_params(*args)
AnyParams.new(args)
end
|
.method_for_authentication(id, params = {}, &block) ⇒ Object
27
28
29
|
# File 'lib/lastfm/method_category/base.rb', line 27
def method_for_authentication(id, params = {}, &block)
__define_method(:request_for_authentication, id, params, &block)
end
|
.method_for_secure_authentication(id, params = {}, &block) ⇒ Object
31
32
33
|
# File 'lib/lastfm/method_category/base.rb', line 31
def method_for_secure_authentication(id, params = {}, &block)
__define_method(:request_for_secure_authentication, id, params, &block)
end
|
.method_with_authentication(id, params = {}, &block) ⇒ Object
23
24
25
|
# File 'lib/lastfm/method_category/base.rb', line 23
def method_with_authentication(id, params = {}, &block)
__define_method(:request_with_authentication, id, params, &block)
end
|
.regular_method(id, params = {}, &block) ⇒ Object
35
36
37
|
# File 'lib/lastfm/method_category/base.rb', line 35
def regular_method(id, params = {}, &block)
__define_method(:request, id, params, &block)
end
|
.write_method(id, params = {}) ⇒ Object
17
18
19
20
21
|
# File 'lib/lastfm/method_category/base.rb', line 17
def write_method(id, params = {})
__define_method(:write_request, id, params) do |response|
response.success?
end
end
|
Instance Method Details
#request(*args) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/lastfm/method_category/base.rb', line 80
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
72
73
74
|
# File 'lib/lastfm/method_category/base.rb', line 72
def request_for_authentication(method, params = {})
request(method, params, :get, true)
end
|
#request_for_secure_authentication(method, params = {}) ⇒ Object
76
77
78
|
# File 'lib/lastfm/method_category/base.rb', line 76
def request_for_secure_authentication(method, params = {})
request(method, params, :post, true, false, true)
end
|
#request_with_authentication(method, params = {}) ⇒ Object
68
69
70
|
# File 'lib/lastfm/method_category/base.rb', line 68
def request_with_authentication(method, params = {})
request(method, params, :get, true, true)
end
|
#write_request(method, params = {}) ⇒ Object
64
65
66
|
# File 'lib/lastfm/method_category/base.rb', line 64
def write_request(method, params = {})
request(method, params, :post, true, true)
end
|