Class: LastFM

Inherits:
Object
  • Object
show all
Includes:
Meta
Defined in:
lib/last_fm.rb,
lib/last_fm/base.rb

Direct Known Subclasses

Album, Artist, Auth, Event, Geo, Group, Library, Playlist, Tag, Tasteometer, Track, User

Defined Under Namespace

Modules: Meta Classes: Album, Artist, Auth, Event, Geo, Group, Library, Playlist, Tag, Tasteometer, Track, User

Constant Summary collapse

VERSION =
'0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Meta

#method_missing

Constructor Details

#initializeLastFM

Returns a new instance of LastFM.



5
6
7
8
# File 'lib/last_fm/base.rb', line 5

def initialize 
  @@cnf  = YAML.load_file "lfm.yml"
  @@url = "http://ws.audioscrobbler.com/2.0/?api_key=#{@@cnf['LAST_FM_KEY']}&"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LastFM::Meta

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/last_fm/base.rb', line 3

def url
  @url
end

Instance Method Details

#albumObject



26
# File 'lib/last_fm/base.rb', line 26

def album() @track            ||= Album.new() end

#artistObject



27
# File 'lib/last_fm/base.rb', line 27

def artist() @artist          ||= Artist.new() end

#eventObject



28
# File 'lib/last_fm/base.rb', line 28

def event() @event            ||= Event.new() end

#geoObject



29
# File 'lib/last_fm/base.rb', line 29

def geo() @geo                ||= Geo.new() end

#get(uri) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/last_fm/base.rb', line 10

def get uri
  begin
    url       = URI.parse(uri)
    req       = Net::HTTP::Get.new(url.path+"?"+url.query)
    @response = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
    result    = Hpricot::XML(@response.body)
  rescue
   puts "Request failed for #{uri} - #{$!}"
  end
end

#groupObject



30
# File 'lib/last_fm/base.rb', line 30

def group() @group            ||= Group.new() end

#lfm_query(method, params) ⇒ Object



21
22
23
24
# File 'lib/last_fm/base.rb', line 21

def lfm_query method,params
  klass = self.class.to_s.gsub("LastFM::","").downcase
  "#{@@url}method=#{klass}.#{method}&#{params.to_query}"
end

#libraryObject



31
# File 'lib/last_fm/base.rb', line 31

def library() @library        ||= Library.new() end

#playlistObject



32
# File 'lib/last_fm/base.rb', line 32

def playlist() @playlist      ||= Playlist.new() end

#tagObject



33
# File 'lib/last_fm/base.rb', line 33

def tag() @tag                ||= Tag.new() end

#tastometerObject



34
# File 'lib/last_fm/base.rb', line 34

def tastometer() @tastometer  ||= Tastometer.new() end

#trackObject



35
# File 'lib/last_fm/base.rb', line 35

def track() @track            ||= Track.new() end

#userObject



36
# File 'lib/last_fm/base.rb', line 36

def user() @user              ||= User.new() end