Class: Lastfm
- Inherits:
-
Object
- Object
- Lastfm
- 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
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #auth ⇒ Object
-
#initialize(api_key, api_secret) ⇒ Lastfm
constructor
A new instance of Lastfm.
- #request(method, params = {}, http_method = :get, with_signature = false, with_session = false) ⇒ Object
- #track ⇒ Object
- #user ⇒ Object
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
#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 # http://www.lastfm.jp/group/Last.fm+Web+Services/forum/21604/_/497978 #params[:format] = format 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.) end response end |