last_fm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/Manifest +15 -0
- data/README.textile +75 -0
- data/Rakefile +12 -0
- data/init.rb +1 -0
- data/last_fm.gemspec +30 -0
- data/lastfm.gemspec +30 -0
- data/lib/last_fm.rb +120 -0
- data/lib/last_fm/models/album.rb +27 -0
- data/lib/last_fm/models/artist.rb +58 -0
- data/lib/last_fm/models/base.rb +67 -0
- data/lib/last_fm/models/chart.rb +4 -0
- data/lib/last_fm/models/event.rb +5 -0
- data/lib/last_fm/models/tag.rb +4 -0
- data/lib/last_fm/models/track.rb +27 -0
- data/lib/last_fm/models/user.rb +34 -0
- metadata +84 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Panagiotis Papadopoulos
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
MIT-LICENSE
|
2
|
+
Manifest
|
3
|
+
README.textile
|
4
|
+
Rakefile
|
5
|
+
init.rb
|
6
|
+
lastfm.gemspec
|
7
|
+
lib/last_fm.rb
|
8
|
+
lib/last_fm/models/album.rb
|
9
|
+
lib/last_fm/models/artist.rb
|
10
|
+
lib/last_fm/models/base.rb
|
11
|
+
lib/last_fm/models/chart.rb
|
12
|
+
lib/last_fm/models/event.rb
|
13
|
+
lib/last_fm/models/tag.rb
|
14
|
+
lib/last_fm/models/track.rb
|
15
|
+
lib/last_fm/models/user.rb
|
data/README.textile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
h1. LastFm
|
2
|
+
|
3
|
+
This library provides some a Ruby interface to interact with the LastFM API. For the time being you can only get data from LastFm.
|
4
|
+
|
5
|
+
First of all I would like to thank ("gordonbisnor":http://github.com/gordonbisnor/) for his "Rails plugin":http://github.com/gordonbisnor/lastfm on which I started building. I started writing this library as I was not satisfied with existing Ruby clients for LastFm. This project is far from being complete and it is not well tested but works quite well for my current project. The reason for writing this library is that most of the existing clients were not Rubyish enough and were tightly attached to Rails. In order to start using this library be sure you have a "LastFm API":http://www.last.fm/api api and secret key.
|
6
|
+
|
7
|
+
h2. Installation
|
8
|
+
|
9
|
+
h4. Gem install
|
10
|
+
|
11
|
+
@sudo gem install lastfm@
|
12
|
+
|
13
|
+
Then in your code require it as
|
14
|
+
|
15
|
+
@require 'last_fm'@
|
16
|
+
|
17
|
+
h2. Example
|
18
|
+
|
19
|
+
Load your configuration
|
20
|
+
|
21
|
+
@LastFm.load_configuration(your_api_key, your_secret+key)@
|
22
|
+
|
23
|
+
Get information for an artist
|
24
|
+
|
25
|
+
@artist = LastFm::Artist.new('Pink Floyd')@
|
26
|
+
|
27
|
+
See the attributes for the artist object
|
28
|
+
|
29
|
+
@artist.methods@
|
30
|
+
|
31
|
+
Get an album of this artist
|
32
|
+
|
33
|
+
@artist.album('The Wall')@
|
34
|
+
|
35
|
+
Get a track of this artist
|
36
|
+
|
37
|
+
@a.track('High Hopes')@
|
38
|
+
|
39
|
+
Get an album
|
40
|
+
|
41
|
+
@LastFm::Album.new('Bonobo','Animal Magic')@
|
42
|
+
|
43
|
+
@LastFm::Album.search('Bonobo','Animal Magic')@
|
44
|
+
|
45
|
+
@LastFm::Artist.search('Bonobo').album('Animal Magic')@
|
46
|
+
|
47
|
+
Get a track
|
48
|
+
|
49
|
+
@LastFm::Track.new('Bonobo','Silver')@
|
50
|
+
|
51
|
+
@LastFm::Track.search('Bonobo','Silver')@
|
52
|
+
|
53
|
+
@LastFm::Track.search('Bonobo').album('Silver')@
|
54
|
+
|
55
|
+
Get user information
|
56
|
+
|
57
|
+
@LastFm::User.new('p3010010').top_albums@
|
58
|
+
|
59
|
+
h2. Dependencies
|
60
|
+
|
61
|
+
The only requirement is ActiveSupport
|
62
|
+
|
63
|
+
h2. Notes
|
64
|
+
|
65
|
+
LastFm gem was developed in a hurry and is not a full blown LastFm client neither extensively tested. Feel free to fork it :)
|
66
|
+
|
67
|
+
h1. License (The MIT License)
|
68
|
+
|
69
|
+
Copyright (c) 2009 Panagiotis Papadopoulos.
|
70
|
+
|
71
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('last_fm', '0.1.0') do |p|
|
6
|
+
p.description = "A Ruby client for LastFm that feels like Ruby."
|
7
|
+
p.url = "http://github.com/PanosJee/LastFm"
|
8
|
+
p.author = "Panagiotis Papadopoulos (PanosJee)"
|
9
|
+
p.email = "panosjee@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lib/last_fm.rb'
|
data/last_fm.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{last_fm}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Panagiotis Papadopoulos (PanosJee)"]
|
9
|
+
s.date = %q{2009-12-08}
|
10
|
+
s.description = %q{A Ruby client for LastFm that feels like Ruby.}
|
11
|
+
s.email = %q{panosjee@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.textile", "lib/last_fm.rb", "lib/last_fm/models/album.rb", "lib/last_fm/models/artist.rb", "lib/last_fm/models/base.rb", "lib/last_fm/models/chart.rb", "lib/last_fm/models/event.rb", "lib/last_fm/models/tag.rb", "lib/last_fm/models/track.rb", "lib/last_fm/models/user.rb"]
|
13
|
+
s.files = ["MIT-LICENSE", "Manifest", "README.textile", "Rakefile", "init.rb", "lastfm.gemspec", "lib/last_fm.rb", "lib/last_fm/models/album.rb", "lib/last_fm/models/artist.rb", "lib/last_fm/models/base.rb", "lib/last_fm/models/chart.rb", "lib/last_fm/models/event.rb", "lib/last_fm/models/tag.rb", "lib/last_fm/models/track.rb", "lib/last_fm/models/user.rb", "last_fm.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/PanosJee/LastFm}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Last_fm", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{last_fm}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{A Ruby client for LastFm that feels like Ruby.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/lastfm.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{lastfm}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Panagiotis Papadopoulos (PanosJee)"]
|
9
|
+
s.date = %q{2009-12-08}
|
10
|
+
s.description = %q{A Ruby client for LastFm that feels like Ruby.}
|
11
|
+
s.email = %q{panosjee@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.textile", "lib/last_fm.rb", "lib/last_fm/models/album.rb", "lib/last_fm/models/artist.rb", "lib/last_fm/models/base.rb", "lib/last_fm/models/chart.rb", "lib/last_fm/models/event.rb", "lib/last_fm/models/tag.rb", "lib/last_fm/models/track.rb", "lib/last_fm/models/user.rb"]
|
13
|
+
s.files = ["MIT-LICENSE", "Manifest", "README.textile", "Rakefile", "init.rb", "lastfm.gemspec", "lib/last_fm.rb", "lib/last_fm/models/album.rb", "lib/last_fm/models/artist.rb", "lib/last_fm/models/base.rb", "lib/last_fm/models/chart.rb", "lib/last_fm/models/event.rb", "lib/last_fm/models/tag.rb", "lib/last_fm/models/track.rb", "lib/last_fm/models/user.rb"]
|
14
|
+
s.homepage = %q{http://github.com/PanosJee/LastFm}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Lastfm", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{lastfm}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{A Ruby client for LastFm that feels like Ruby.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/lib/last_fm.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'activesupport'
|
5
|
+
require 'net/http'
|
6
|
+
require 'digest'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
# The models
|
10
|
+
require 'last_fm/models/base.rb'
|
11
|
+
require 'last_fm/models/tag.rb'
|
12
|
+
require 'last_fm/models/user.rb'
|
13
|
+
require 'last_fm/models/event.rb'
|
14
|
+
require 'last_fm/models/chart.rb'
|
15
|
+
require 'last_fm/models/track.rb'
|
16
|
+
require 'last_fm/models/artist.rb'
|
17
|
+
require 'last_fm/models/album.rb'
|
18
|
+
|
19
|
+
module LastFm
|
20
|
+
|
21
|
+
class << self
|
22
|
+
|
23
|
+
def load_configuration(key, secret = nil, prefix = nil)
|
24
|
+
@key = key
|
25
|
+
@secret = secret
|
26
|
+
@prefix = prefix || "/2.0/?api_key=#{@key}&method="
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_signature(method,params)
|
31
|
+
signature = []
|
32
|
+
signature << 'method' + method
|
33
|
+
params.each_pair do |key,value|
|
34
|
+
signature << key.to_s + value
|
35
|
+
end
|
36
|
+
signature = signature.sort.join + @secret
|
37
|
+
return Digest::MD5.hexdigest(signature)
|
38
|
+
end
|
39
|
+
|
40
|
+
# fetch lastfm
|
41
|
+
def fetch_data(path)
|
42
|
+
http = Net::HTTP.new("ws.audioscrobbler.com",80)
|
43
|
+
resp, data = http.get(urlize(@prefix+path+"&api_key="+@key))
|
44
|
+
return resp.code == "200" ? data : false
|
45
|
+
end
|
46
|
+
|
47
|
+
def urlize(string)
|
48
|
+
return string.gsub(/\ +/, '%20')
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_session(token)
|
52
|
+
signature = get_signature('auth.getsession',{:api_key => @key, :token => token})
|
53
|
+
if @session = connect_with_auth('auth.getsession',{ :api_key => @ey, :token => token, :signature => signature })
|
54
|
+
session[:lastfm_name] = @session['session']['name']
|
55
|
+
session[:lastfm_key] = @session['session']['key']
|
56
|
+
else
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
#get_lastfm
|
62
|
+
def request(method,params,type='hash')
|
63
|
+
http = Net::HTTP.new("ws.audioscrobbler.com",80)
|
64
|
+
path = @prefix + method
|
65
|
+
params.each_pair do |key,value|
|
66
|
+
path << "&#{key}=#{value}"
|
67
|
+
end
|
68
|
+
resp, data = http.get(urlize(path))
|
69
|
+
if resp.code == "200"
|
70
|
+
if type == 'hash'
|
71
|
+
hash = Hash.from_xml(data)['lfm']
|
72
|
+
hash.shift
|
73
|
+
return hash
|
74
|
+
else
|
75
|
+
return data
|
76
|
+
end
|
77
|
+
else
|
78
|
+
return resp.body
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def authenticated_request(method, params,type = 'hash')
|
83
|
+
http = Net::HTTP.new("ws.audioscrobbler.com",80)
|
84
|
+
path = @prefix + method
|
85
|
+
params.each_pair do |key,value|
|
86
|
+
path << "&#{key}=#{value}"
|
87
|
+
end
|
88
|
+
path << '&api_sig=' + get_signature(method,params)
|
89
|
+
resp, data = http.get(urlize(path))
|
90
|
+
if resp.code == "200"
|
91
|
+
if type == 'hash'
|
92
|
+
hash = Hash.from_xml(data)['lfm']
|
93
|
+
hash.shift
|
94
|
+
return hash
|
95
|
+
else
|
96
|
+
return data
|
97
|
+
end
|
98
|
+
else
|
99
|
+
return false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def post(method,posted)
|
104
|
+
posted[:api_key] = @key
|
105
|
+
posted[:sk] = session[:lastfm_key]
|
106
|
+
signature = get_signature(method,posted)
|
107
|
+
posted[:api_sig] = get_signature(method,posted)
|
108
|
+
posted[:method] = method
|
109
|
+
resp = Net::HTTP.post_form(URI.parse('http://ws.audioscrobbler.com/2.0/'),posted)
|
110
|
+
case resp
|
111
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
112
|
+
return true
|
113
|
+
else
|
114
|
+
return false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LastFm
|
2
|
+
class Album < Base
|
3
|
+
|
4
|
+
def initialize(artist,name)
|
5
|
+
super(name)
|
6
|
+
@attributes = self.info(artist) if @attributes == {} and !artist.blank?
|
7
|
+
_process_attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
def info(artist, options = {})
|
11
|
+
params = ""
|
12
|
+
options.each_pair { |key,value| params += "&#{key}=#{value}" }
|
13
|
+
lfm_path = "album.getinfo&artist=#{artist}&album=#{@name}#{params}"
|
14
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
15
|
+
return Hash.from_xml(lfm_data)['lfm']['album']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.search(artist,album)
|
19
|
+
self.new(artist,album)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def _process_attributes; end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module LastFm
|
2
|
+
class Artist < Base
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
super(name)
|
6
|
+
@attributes = self.info if @attributes == {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def info
|
10
|
+
lfm_path = "artist.getinfo&artist=#{@name}"
|
11
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
12
|
+
return Hash.from_xml(lfm_data)['lfm']['artist']
|
13
|
+
end
|
14
|
+
|
15
|
+
# Work on tag object
|
16
|
+
def top_tags
|
17
|
+
lfm_path = "artist.getTopTags&artist=#{@name}"
|
18
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
19
|
+
return Tag.create_from_hash(Hash.from_xml(lfm_data)['lfm']['toptags']['tag'])
|
20
|
+
end
|
21
|
+
|
22
|
+
# Work on event object
|
23
|
+
def events
|
24
|
+
lfm_path = "artist.getevents&artist=#{@name}"
|
25
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
26
|
+
return Event.create_from_hash(Hash.from_xml(lfm_data)['lfm']['events']['event'])
|
27
|
+
end
|
28
|
+
|
29
|
+
def similar(limit = 7)
|
30
|
+
lfm_path = "artist.getsimilar&artist=#{@name}&limit=#{limit}"
|
31
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
32
|
+
return Event.create_from_hash(Hash.from_xml(lfm_data)['lfm']['similarartists']['artist'])
|
33
|
+
end
|
34
|
+
|
35
|
+
# Work on album object
|
36
|
+
def top_albums
|
37
|
+
lfm_path = "artist.topAlbums&artist=#{@name}"
|
38
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
39
|
+
return Album.create_from_hash(Hash.from_xml(lfm_data)['lfm']['topalbums']['album'])
|
40
|
+
end
|
41
|
+
|
42
|
+
# work on track object
|
43
|
+
def top_tracks
|
44
|
+
lfm_path = "artist.topTracks&artist=#{@name}"
|
45
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
46
|
+
return Track.create_from_hash(Hash.from_xml(lfm_data)['lfm']['toptracks']['track'])
|
47
|
+
end
|
48
|
+
|
49
|
+
def track(track_name)
|
50
|
+
Track.search(@name, track_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def album(album_name)
|
54
|
+
Album.search(@name, album_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module LastFm
|
2
|
+
class Base
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def search(name)
|
6
|
+
self.new(name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_from_hash(data)
|
10
|
+
if data.class == Array
|
11
|
+
models = []
|
12
|
+
data.each do |d|
|
13
|
+
if d.class == Hash
|
14
|
+
name = (d['name'] || d['title']) || d['id']
|
15
|
+
n = self.new(name) rescue self.new(nil, name)
|
16
|
+
n.attributes = d
|
17
|
+
models.push(n)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
return models
|
21
|
+
else
|
22
|
+
name = (data['name'] || data['title']) || data['id']
|
23
|
+
n = self.new(name)
|
24
|
+
n.attributes = data
|
25
|
+
return n
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def initialize(name)
|
32
|
+
@name = name
|
33
|
+
@attributes = Hash.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def name
|
37
|
+
@name
|
38
|
+
end
|
39
|
+
|
40
|
+
def name=(n)
|
41
|
+
@name = n
|
42
|
+
end
|
43
|
+
|
44
|
+
def attributes=(h)
|
45
|
+
@attributes = h
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_xml_attributes(elements)
|
49
|
+
h = Hash.new
|
50
|
+
elements.each { |e|
|
51
|
+
# do somethings about nested and cdata !
|
52
|
+
name = e.name == "image" ? 'image_'+e.attributes['size'] : e.name
|
53
|
+
h[name] = e.text
|
54
|
+
}
|
55
|
+
return h
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def method_missing(sym, *args, &block)
|
60
|
+
return @attributes[sym.to_s] if @attributes.has_key?(sym.to_s)
|
61
|
+
end
|
62
|
+
|
63
|
+
def methods
|
64
|
+
@attributes.keys
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LastFm
|
2
|
+
class Track < Base
|
3
|
+
|
4
|
+
def initialize(artist,name)
|
5
|
+
super(name)
|
6
|
+
@attributes = self.info(artist) if @attributes == {} and !artist.blank?
|
7
|
+
_process_attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
def info(artist, options = {})
|
11
|
+
params = ""
|
12
|
+
options.each_pair { |key,value| params += "&#{key}=#{value}" }
|
13
|
+
lfm_path = "track.getinfo&artist=#{artist}&track=#{@name}#{params}"
|
14
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
15
|
+
return Hash.from_xml(lfm_data)['lfm']['track']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.search(artist,track)
|
19
|
+
self.new(artist,track)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def _process_attributes; end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LastFm
|
2
|
+
class User < Base
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
super(name)
|
6
|
+
end
|
7
|
+
|
8
|
+
def weekly_album_chart
|
9
|
+
lfm_path = "user.weeklyalbumchart&user=#{@name}"
|
10
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
11
|
+
return Album.create_from_hash(Hash.from_xml(lfm_data)['lfm']['weeklyalbumchart']['album'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def top_albums
|
15
|
+
lfm_path = "user.gettopalbums&user=#{@name}"
|
16
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
17
|
+
return Album.create_from_hash(Hash.from_xml(lfm_data)['lfm']['topalbums']['album'])
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def weekly_artists_chart
|
22
|
+
lfm_path = "user.getweeklyartistchart&user=#{@name}"
|
23
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
24
|
+
return Artist.create_from_hash(Hash.from_xml(lfm_data)['lfm']['weeklyartistchart']['artist'])
|
25
|
+
end
|
26
|
+
|
27
|
+
def top_artists
|
28
|
+
lfm_path = "user.gettopartists&user=#{@name}"
|
29
|
+
lfm_data = LastFm::fetch_data(lfm_path)
|
30
|
+
return Artist.create_from_hash(Hash.from_xml(lfm_data)['lfm']['topartists']['artist'])
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: last_fm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Panagiotis Papadopoulos (PanosJee)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-08 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby client for LastFm that feels like Ruby.
|
17
|
+
email: panosjee@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
- lib/last_fm.rb
|
25
|
+
- lib/last_fm/models/album.rb
|
26
|
+
- lib/last_fm/models/artist.rb
|
27
|
+
- lib/last_fm/models/base.rb
|
28
|
+
- lib/last_fm/models/chart.rb
|
29
|
+
- lib/last_fm/models/event.rb
|
30
|
+
- lib/last_fm/models/tag.rb
|
31
|
+
- lib/last_fm/models/track.rb
|
32
|
+
- lib/last_fm/models/user.rb
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- Manifest
|
36
|
+
- README.textile
|
37
|
+
- Rakefile
|
38
|
+
- init.rb
|
39
|
+
- lastfm.gemspec
|
40
|
+
- lib/last_fm.rb
|
41
|
+
- lib/last_fm/models/album.rb
|
42
|
+
- lib/last_fm/models/artist.rb
|
43
|
+
- lib/last_fm/models/base.rb
|
44
|
+
- lib/last_fm/models/chart.rb
|
45
|
+
- lib/last_fm/models/event.rb
|
46
|
+
- lib/last_fm/models/tag.rb
|
47
|
+
- lib/last_fm/models/track.rb
|
48
|
+
- lib/last_fm/models/user.rb
|
49
|
+
- last_fm.gemspec
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/PanosJee/LastFm
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --line-numbers
|
57
|
+
- --inline-source
|
58
|
+
- --title
|
59
|
+
- Last_fm
|
60
|
+
- --main
|
61
|
+
- README.textile
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "1.2"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project: last_fm
|
79
|
+
rubygems_version: 1.3.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: A Ruby client for LastFm that feels like Ruby.
|
83
|
+
test_files: []
|
84
|
+
|