Class: Lastfm
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/lastfm.rb,
lib/lastfm/util.rb,
lib/lastfm/response.rb,
lib/lastfm/method_category/geo.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/track.rb,
lib/lastfm/method_category/artist.rb,
lib/lastfm/method_category/library.rb
Defined Under Namespace
Modules: MethodCategory
Classes: ApiError, Error, Response, Util
Constant Summary
collapse
- API_ROOT =
'http://ws.audioscrobbler.com/2.0'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_key, api_secret) ⇒ Lastfm
Returns a new instance of Lastfm.
35
36
37
38
|
# File 'lib/lastfm.rb', line 35
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.
23
24
25
|
# File 'lib/lastfm.rb', line 23
def session
@session
end
|
Instance Method Details
#request(method, params = {}, http_method = :get, with_signature = false, with_session = false) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/lastfm.rb', line 68
def request(method, params = {}, http_method = :get, with_signature = false, with_session = 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
response = Response.new(self.class.send(http_method, '/', (http_method == :post ? :body : :query) => params).body)
unless response.success?
raise ApiError.new(response.message, response.error)
end
response
end
|