Class: Lastfm
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/lastfm.rb,
lib/lastfm/response.rb,
lib/lastfm/method_category.rb,
lib/lastfm/method_category/auth.rb,
lib/lastfm/method_category/user.rb,
lib/lastfm/method_category/track.rb
Defined Under Namespace
Classes: ApiError, Auth, Error, MethodCategory, Response, Track, User
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.
23
24
25
26
|
# File 'lib/lastfm.rb', line 23
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.
18
19
20
|
# File 'lib/lastfm.rb', line 18
def session
@session
end
|
Instance Method Details
#auth ⇒ Object
28
29
30
|
# File 'lib/lastfm.rb', line 28
def auth
Auth.new(self)
end
|
#request(method, params = {}, http_method = :get, with_signature = false, with_session = false) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/lastfm.rb', line 40
def request(method, params = {}, http_method = :get, with_signature = false, with_session = false)
params[:method] = method
params[:api_key] = @api_key
params.update(:sk => @session) if with_session
params.update(:api_sig => Digest::MD5.hexdigest(build_method_signature(params))) if with_signature
params.update(:format => 'json')
response = Response.new(self.class.send(http_method, '/', (http_method == :post ? :body : :query) => params).body)
unless response.success?
raise ApiError.new(response.message)
end
response
end
|
#track ⇒ Object
32
33
34
|
# File 'lib/lastfm.rb', line 32
def track
Track.new(self)
end
|
#user ⇒ Object
36
37
38
|
# File 'lib/lastfm.rb', line 36
def user
User.new(self)
end
|