class Lastfm

Attributes

session[RW]

Public Class Methods

new(api_key, api_secret) click to toggle source
# File lib/lastfm.rb, line 37
def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
end

Public Instance Methods

album() click to toggle source
# File lib/lastfm.rb, line 42
def album
  MethodCategory::Album.new(self)
end
artist() click to toggle source
# File lib/lastfm.rb, line 46
def artist
  MethodCategory::Artist.new(self)
end
auth() click to toggle source
# File lib/lastfm.rb, line 50
def auth
  MethodCategory::Auth.new(self)
end
chart() click to toggle source
# File lib/lastfm.rb, line 86
def chart
  MethodCategory::Chart.new(self)
end
event() click to toggle source
# File lib/lastfm.rb, line 54
def event
  MethodCategory::Event.new(self)
end
geo() click to toggle source
# File lib/lastfm.rb, line 58
def geo
  MethodCategory::Geo.new(self)
end
group() click to toggle source
# File lib/lastfm.rb, line 62
def group
  MethodCategory::Group.new(self)
end
library() click to toggle source
# File lib/lastfm.rb, line 66
def library
  MethodCategory::Library.new(self)
end
radio() click to toggle source
# File lib/lastfm.rb, line 90
def radio
  MethodCategory::Radio.new(self)
end
request(method, params = {}, http_method = :get, with_signature = false, with_session = false, use_https = false) click to toggle source
# File lib/lastfm.rb, line 94
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

  # 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

  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
tag() click to toggle source
# File lib/lastfm.rb, line 70
def tag
  MethodCategory::Tag.new(self)
end
tasteometer() click to toggle source
# File lib/lastfm.rb, line 74
def tasteometer
  MethodCategory::Tasteometer.new(self)
end
track() click to toggle source
# File lib/lastfm.rb, line 78
def track
  MethodCategory::Track.new(self)
end
user() click to toggle source
# File lib/lastfm.rb, line 82
def user
  MethodCategory::User.new(self)
end

Private Instance Methods

build_method_signature(params) click to toggle source
# File lib/lastfm.rb, line 128
def build_method_signature(params)
  params.to_a.sort_by do |param|
    param.first.to_s
  end.inject('') do |result, param|
    result + param.join('')
  end + @api_secret
end