Class: Lastfm

Inherits:
Object
  • 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/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/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

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.



39
40
41
42
# File 'lib/lastfm.rb', line 39

def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



27
28
29
# File 'lib/lastfm.rb', line 27

def session
  @session
end

Instance Method Details

#albumObject



44
45
46
# File 'lib/lastfm.rb', line 44

def album
  MethodCategory::Album.new(self)
end

#artistObject



48
49
50
# File 'lib/lastfm.rb', line 48

def artist
  MethodCategory::Artist.new(self)
end

#authObject



52
53
54
# File 'lib/lastfm.rb', line 52

def auth
  MethodCategory::Auth.new(self)
end

#chartObject



84
85
86
# File 'lib/lastfm.rb', line 84

def chart
  MethodCategory::Chart.new(self)
end

#eventObject



56
57
58
# File 'lib/lastfm.rb', line 56

def event
  MethodCategory::Event.new(self)
end

#geoObject



60
61
62
# File 'lib/lastfm.rb', line 60

def geo
  MethodCategory::Geo.new(self)
end

#libraryObject



64
65
66
# File 'lib/lastfm.rb', line 64

def library
  MethodCategory::Library.new(self)
end

#request(method, params = {}, http_method = :get, with_signature = false, with_session = false) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/lastfm.rb', line 88

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

  # 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

  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

#tagObject



68
69
70
# File 'lib/lastfm.rb', line 68

def tag
  MethodCategory::Tag.new(self)
end

#tasteometerObject



72
73
74
# File 'lib/lastfm.rb', line 72

def tasteometer
  MethodCategory::Tasteometer.new(self)
end

#trackObject



76
77
78
# File 'lib/lastfm.rb', line 76

def track
  MethodCategory::Track.new(self)
end

#userObject



80
81
82
# File 'lib/lastfm.rb', line 80

def user
  MethodCategory::User.new(self)
end