Class: Lastfm
- Inherits:
-
Object
show all
- Defined in:
- lib/lastfm.rb,
lib/lastfm/util.rb,
lib/lastfm/response.rb,
lib/lastfm/method_category/geo.rb,
lib/lastfm/method_category/tag.rb,
lib/lastfm/method_category/auth.rb,
lib/lastfm/method_category/base.rb,
lib/lastfm/method_category/user.rb,
lib/lastfm/method_category/album.rb,
lib/lastfm/method_category/chart.rb,
lib/lastfm/method_category/event.rb,
lib/lastfm/method_category/radio.rb,
lib/lastfm/method_category/track.rb,
lib/lastfm/method_category/artist.rb,
lib/lastfm/method_category/library.rb,
lib/lastfm/method_category/tasteometer.rb
Defined Under Namespace
Modules: MethodCategory
Classes: ApiError, Error, Response, Util
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_key, api_secret) ⇒ Lastfm
Returns a new instance of Lastfm.
37
38
39
40
|
# File 'lib/lastfm.rb', line 37
def initialize(api_key, api_secret)
@api_key = api_key
@api_secret = api_secret
end
|
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
25
26
27
|
# File 'lib/lastfm.rb', line 25
def session
@session
end
|
Instance Method Details
#request(method, params = {}, http_method = :get, with_signature = false, with_session = false, use_https = false) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/lastfm.rb', line 90
def request(method, params = {}, http_method = :get, with_signature = false, with_session = false, use_https = false)
params[:method] = method
params[:api_key] = @api_key
params.each do |k, v|
if v.nil?
params.delete(k)
end
end
params.update(:sk => @session) if with_session
params.update(:api_sig => Digest::MD5.hexdigest(build_method_signature(params))) if with_signature
request_args = [http_method, '/', (http_method == :post ? :body : :query) => params]
response = if use_https
HTTPSRequest.send(*request_args)
else
HTTPRequest.send(*request_args)
end
response = Response.new(response.body)
unless response.success?
raise ApiError.new(response.message, response.error)
end
response
end
|