rscrobbler 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTc2YTM0NGVjZWU5NzRiNWRlYzZhYjVkZTEwNmIwNzM1ZDk1NzVmYw==
5
+ data.tar.gz: !binary |-
6
+ MGJiMzZhNjRhMmMwOTJlZjkzYzE4ODQzYmJlYThhMmU2ZDYwNTIzMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWUyODBhMWU3YmE0ZTMxYmZkNDAyOTFiZjk2NmEzMmMwMDRmYjk0M2UwMjk0
10
+ Y2I5YTVhNGY5Mzc4MGJhOTdkZTUzMmZlOWNiZjRjYzkxYjY3NDdhZGI1NTgw
11
+ NDU1M2YwMmZmMmFiYzdmZDQ4ZTEwYWZlM2ZjMWM3NDYzMDNmYTI=
12
+ data.tar.gz: !binary |-
13
+ NmFmMzBhZDMzNTY2ZGM2MDFmNzZjZDE2NjM3YTQ2ZmU3ZTMyOGRmZDY4NjY2
14
+ Y2E3MzQ4NjM2N2JiNmE3ZjMyMjAyZjMzODE1MDU1MjYyZTk2YzQ5NDViOWRl
15
+ YWQ1MTc4ODlkODc1MjgyNjIxZDNmMzFhODFhMTQ1ZmE1ODQzMDg=
data/lib/lastfm/album.rb CHANGED
@@ -1,55 +1,197 @@
1
- module LastFM
2
-
3
- # @attr [LastFM::Artist, String] artist
4
- # @attr [Fixnum] id
5
- # @attr [Hash] images
6
- # @attr [Fixnum] listeners
7
- # @attr [String] mbid
8
- # @attr [String] name
9
- # @attr [Fixnum] playcount
10
- # @attr [Time] release_date
11
- # @attr [Boolean] streamable
12
- # @attr [Array<LastFM::Tag>] tags
13
- # @attr [Array<LastFM::Track>] tracks
14
- # @attr [String] url
15
- # @attr [LastFM::Wiki] wiki
16
- class Album < Struct.new(:artist, :id, :images, :listeners, :mbid, :name, :playcount, :release_date, :streamable, :tags, :tracks, :url, :wiki)
17
-
18
- def update_from_node(node)
19
- case node.name.to_sym
20
- when :name, :title
21
- self.name = node.content
22
- when :artist
23
- self.artist = (node.find('*').count == 0) ? node.content : LastFM::Artist.from_xml(node)
24
- when :id
25
- self.id = node.content.to_i
26
- when :mbid
27
- self.mbid = node.content
28
- when :url
29
- self.url = node.content
30
- when :releasedate
31
- self.release_date = Time.parse(node.content) rescue nil
32
- when :image
33
- self.images ||= {}
34
- self.images.merge!({node['size'].to_sym => node.content})
35
- when :listeners
36
- self.listeners = node.content.to_i
37
- when :playcount
38
- self.playcount = node.content.to_i
39
- when :streamable
40
- self.streamable = (node.content == '1')
41
- when :tracks
42
- self.tracks = node.find('track').map do |track|
43
- LastFM::Track.from_xml(track, :album => self.name, :position => track['rank'].to_i)
44
- end
45
- when :toptags
46
- self.tags = node.find('tag').map do |tag|
47
- LastFM::Tag.from_xml(tag)
48
- end
49
- when :wiki
50
- self.wiki = LastFM::Wiki.from_xml(node)
51
- end
52
- end
53
-
54
- end
55
- end
1
+ module LastFM
2
+
3
+ # @attr [LastFM::Artist, String] artist
4
+ # @attr [Fixnum] id
5
+ # @attr [Hash] images
6
+ # @attr [Fixnum] listeners
7
+ # @attr [String] mbid
8
+ # @attr [String] name
9
+ # @attr [Fixnum] playcount
10
+ # @attr [Time] release_date
11
+ # @attr [Boolean] streamable
12
+ # @attr [Array<LastFM::Tag>] tags
13
+ # @attr [Array<LastFM::Track>] tracks
14
+ # @attr [String] url
15
+ # @attr [LastFM::Wiki] wiki
16
+ class Album < Struct.new(:artist, :id, :images, :listeners, :mbid, :name, :playcount, :release_date, :streamable, :tags, :tracks, :url, :wiki)
17
+
18
+ # API Methods
19
+ class << self
20
+
21
+ # Tag an album using a list of user supplied tags.
22
+ #
23
+ # @option params [String, required] :artist the artist name
24
+ # @option params [String, required] :album the album name
25
+ # @option params [Array, required] :tags up to 10 tags to apply to this album
26
+ # @see http://www.last.fm/api/show?service=302
27
+ def add_tags( params )
28
+ LastFM.requires_authentication
29
+ LastFM.post( "album.addTags", params )
30
+ end
31
+
32
+ # Get a list of buy links for an album.
33
+ #
34
+ # @option params [String, required unless :mbid] :artist the artist name
35
+ # @option params [String, required unless :mbid] :album the album name
36
+ # @option params [String, required] :country a country name, as defined by ISO 3166-1
37
+ # @option params [String, optional] :mbid the musicbrainz id for the album
38
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
39
+ # @return [Array<LastFM::Buylink>] collection of links where this album can be bought or downloaded
40
+ # @see http://www.last.fm/api/show?service=429
41
+ def get_buylinks( params )
42
+ xml = LastFM.get( "album.getBuylinks", params )
43
+ [:physical, :download].each_with_object([]) do |type, buylinks|
44
+ xml.find("affiliations/#{type}s/affiliation").each do |buylink|
45
+ buylinks << LastFM::Buylink.from_xml( buylink, :type => type )
46
+ end
47
+ end
48
+ end
49
+
50
+ # Get the metadata for an album.
51
+ #
52
+ # @option params [String, required unless :mbid] :artist the artist name
53
+ # @option params [String, required unless :mbid] :album the album name
54
+ # @option params [String, optional] :mbid the musicbrainz id for the album
55
+ # @option params [String, optional] :lang the language to return the biography in, expressed as an ISO 639 alpha-2 code
56
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
57
+ # @option params [String, optional] :username username whose playcount for this album is to be returned in the reponse
58
+ # @return [LastFM::Album] album constructed from the metadata contained in the response
59
+ # @see http://www.last.fm/api/show?service=290
60
+ def get_info( params )
61
+ xml = LastFM.get( "album.getInfo", params )
62
+ LastFM::Album.from_xml( xml )
63
+ end
64
+
65
+ # Get shouts for an album.
66
+ #
67
+ # @option params [String, required unless :mbid] :artist the artist name
68
+ # @option params [String, required unless :mbid] :album the album name
69
+ # @option params [String, optional] :mbid the musicbrainz id for the album
70
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
71
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
72
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
73
+ # @return [Array<LastFM::Shout>] collection of shouts
74
+ # @see http://www.last.fm/api/show?service=450
75
+ def get_shouts( params )
76
+ xml = LastFM.get( "album.getShouts", params )
77
+ xml.find('shouts/shout').map do |shout|
78
+ LastFM::Shout.from_xml( shout )
79
+ end
80
+ end
81
+
82
+ # Get the tags applied by an individual user to an album.
83
+ #
84
+ # @option params [String, required unless :mbid] :artist the artist name
85
+ # @option params [String, required unless :mbid] :album the album name
86
+ # @option params [String, optional] :mbid the musicbrainz id for the album
87
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
88
+ # @option params [String, optional] :user if called in non-authenticated mode you must specify the user to look up
89
+ # @see http://www.last.fm/api/show?service=317
90
+ def get_tags( params )
91
+ secure = !params.include?(:user)
92
+ LastFM.requires_authentication if secure
93
+ xml = LastFM.get( "album.getTags", params, secure )
94
+ xml.find('tags/tag').map do |tag|
95
+ LastFM::Tag.from_xml( tag )
96
+ end
97
+ end
98
+
99
+ # Get the top tags for an album, ordered by popularity.
100
+ #
101
+ # @option params [String, required unless :mbid] :artist the artist name
102
+ # @option params [String, required unless :mbid] :album the album name
103
+ # @option params [String, optional] :mbid the musicbrainz id for the album
104
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
105
+ # @return [Array<LastFM::Tag>] list of tags sorted by popularity
106
+ # @see http://www.last.fm/api/show?service=438
107
+ def get_top_tags( params )
108
+ xml = LastFM.get( "album.getTopTags", params )
109
+ xml.find('toptags/tag').map do |tag|
110
+ LastFM::Tag.from_xml( tag )
111
+ end
112
+ end
113
+
114
+ # Remove a user's tag from an album.
115
+ #
116
+ # @option params [String, required] :artist the artist name
117
+ # @option params [String, required] :album the album name
118
+ # @option params [String, required] :tag a single user tag to remove from this album
119
+ # @see http://www.last.fm/api/show?service=314
120
+ def remove_tag( params )
121
+ LastFM.requires_authentication
122
+ LastFM.post( "album.removeTag", params )
123
+ end
124
+
125
+ # Search for an album by name. Returns album matches sorted by relevance.
126
+ #
127
+ # @option params [String, required] :album the album name
128
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
129
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
130
+ # @return [Array<LastFM::Album>] list of albums sorted by relevance
131
+ # @see http://www.last.fm/api/show?service=357
132
+ def search( params )
133
+ xml = LastFM.get( "album.search", params )
134
+ xml.find('results/albummatches/album').map do |album|
135
+ LastFM::Album.from_xml( album )
136
+ end
137
+ end
138
+
139
+ # Share an album with one or more Last.fm users or other friends.
140
+ #
141
+ # @option params [String, required] :artist the artist name
142
+ # @option params [String, required] :album the album name
143
+ # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
144
+ # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
145
+ # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
146
+ # @see http://www.last.fm/api/show?service=436
147
+ def share( params )
148
+ LastFM.requires_authentication
149
+ LastFM.post( "album.share", params )
150
+ end
151
+
152
+ end
153
+
154
+ private
155
+
156
+ # Compensate for discrepancies between XML response and model attributes
157
+ alias :image= :images=
158
+ alias :title= :name=
159
+ alias :releasedate= :release_date=
160
+ alias :toptags= :tags=
161
+
162
+ def parse_node(member, node)
163
+ case member
164
+ when :artist
165
+ if node.find('*').count == 0
166
+ node.content
167
+ else
168
+ LastFM::Artist.from_xml(node)
169
+ end
170
+ when :id, :listeners, :playcount
171
+ node.content.to_i
172
+ when :images
173
+ (self.images || {}).merge(node['size'].to_sym => node.content)
174
+ when :mbid, :name, :url
175
+ node.content
176
+ when :release_date
177
+ Time.parse(node.content) rescue nil
178
+ when :streamable
179
+ node.content == '1'
180
+ when :tags
181
+ node.find('tag').map do |tag|
182
+ LastFM::Tag.from_xml(tag)
183
+ end
184
+ when :tracks
185
+ node.find('track').map do |track|
186
+ LastFM::Track.from_xml(track,
187
+ :album => self.name,
188
+ :position => track['rank'].to_i
189
+ )
190
+ end
191
+ when :wiki
192
+ LastFM::Wiki.from_xml(node)
193
+ end
194
+ end
195
+
196
+ end
197
+ end
data/lib/lastfm/artist.rb CHANGED
@@ -1,48 +1,291 @@
1
- module LastFM
2
-
3
- # @attr [Hash] images
4
- # @attr [Fixnum] listeners
5
- # @attr [String] mbid
6
- # @attr [String] name
7
- # @attr [Fixnum] playcount
8
- # @attr [Array] similar
9
- # @attr [Boolean] streamable
10
- # @attr [Array] tags
11
- # @attr [String] url
12
- # @attr [LastFM::Wiki] wiki
13
- class Artist < Struct.new(:images, :listeners, :mbid, :name, :playcount, :similar, :streamable, :tags, :url, :wiki)
14
-
15
- def update_from_node(node)
16
- case node.name.to_sym
17
- when :name
18
- self.name = node.content
19
- when :mbid
20
- self.mbid = node.content
21
- when :url
22
- self.url = node.content
23
- when :image
24
- self.images ||= {}
25
- self.images.merge!({node['size'].to_sym => node.content})
26
- when :streamable
27
- self.streamable = (node.content == '1')
28
- when :listeners
29
- self.listeners = node.content.to_i
30
- when :playcount
31
- self.playcount = node.content.to_i
32
- when :stats # nested listeners and playcount
33
- node.find('*').each{|child| self.update_from_node(child)}
34
- when :similar
35
- self.similar = node.find('artist').map do |artist|
36
- LastFM::Artist.from_xml(artist)
37
- end
38
- when :tags
39
- self.tags = node.find('tag').map do |tag|
40
- LastFM::Tag.from_xml(tag)
41
- end
42
- when :bio
43
- self.wiki = LastFM::Wiki.from_xml(node)
44
- end
45
- end
46
-
47
- end
48
- end
1
+ module LastFM
2
+
3
+ # @attr [Hash] images
4
+ # @attr [Fixnum] listeners
5
+ # @attr [String] mbid
6
+ # @attr [String] name
7
+ # @attr [Fixnum] playcount
8
+ # @attr [Array] similar
9
+ # @attr [Boolean] streamable
10
+ # @attr [Array] tags
11
+ # @attr [String] url
12
+ # @attr [LastFM::Wiki] wiki
13
+ class Artist < Struct.new(:images, :listeners, :mbid, :name, :playcount, :similar, :streamable, :tags, :url, :wiki)
14
+
15
+ # API Methods
16
+ class << self
17
+
18
+ # Tag an artist with one or more user supplied tags.
19
+ #
20
+ # @option params [String, required] :artist the artist name
21
+ # @option params [Array, required] :tags up to 10 tags to apply to this artist
22
+ # @see http://www.last.fm/api/show/?service=303
23
+ def add_tags( params )
24
+ LastFM.requires_authentication
25
+ LastFM.post( "artist.addTags", params )
26
+ end
27
+
28
+ # Check whether the supplied artist has a correction to a canonical artist.
29
+ #
30
+ # @option params [String, required] :artist the artist name
31
+ # @return [Array<LastFM::Artist>] list of suggestion corrections, in order of similarity
32
+ # @see http://www.last.fm/api/show/?service=446
33
+ def get_correction( params )
34
+ xml = LastFM.get( "artist.getCorrection", params )
35
+ xml.find('corrections/correction/artist').map do |correction|
36
+ LastFM::Artist.from_xml( correction )
37
+ end
38
+ end
39
+
40
+ # Get a list of upcoming events for this artist.
41
+ #
42
+ # @option params [String, required unless :mbid] :artist the artist name
43
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
44
+ # @option params [Boolean, optional] :festivalsonly whether only festivals should be returned, or all events
45
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
46
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
47
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
48
+ # @see http://www.last.fm/api/show/?service=117
49
+ def get_events( params )
50
+ xml = LastFM.get( "artist.getEvents", params )
51
+ xml.find('events/event').map do |event|
52
+ LastFM::Event.from_xml( event )
53
+ end
54
+ end
55
+
56
+ # Get images for this artist in a variety of sizes.
57
+ #
58
+ # @option params [String, required unless :mbid] :artist the artist name
59
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
60
+ # @option params [Symbol, optional] :order sort ordering can be either :popularity (default) or :dateadded
61
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
62
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
63
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
64
+ # @see http://www.last.fm/api/show/?service=407
65
+ def get_images( params )
66
+ LastFM.get( "artist.getImages", params )
67
+ end
68
+
69
+ # Get the metadata for an artist. Includes biography.
70
+ #
71
+ # @option params [String, required unless :mbid] :artist the artist name
72
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
73
+ # @option params [String, optional] :lang the language to return the biography in, expressed as an ISO 639 alpha-2 code
74
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
75
+ # @option params [String, optional] :username username whose playcount for this artist is to be returned in the reponse
76
+ # @return [LastFM::Artist] artist constructed from the metadata contained in the response
77
+ # @see http://www.last.fm/api/show/?service=267
78
+ def get_info( params )
79
+ xml = LastFM.get( "artist.getInfo", params )
80
+ LastFM::Artist.from_xml( xml )
81
+ end
82
+
83
+ # Get a paginated list of all the events this artist has played at in the past.
84
+ #
85
+ # @option params [String, required unless :mbid] :artist the artist name
86
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
87
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
88
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
89
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
90
+ # @see http://www.last.fm/api/show/?service=428
91
+ def get_past_events( params )
92
+ LastFM.get( "artist.getPastEvents", params )
93
+ end
94
+
95
+ # Get a podcast of free mp3s based on an artist.
96
+ #
97
+ # @option params [String, required unless :mbid] :artist the artist name
98
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
99
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
100
+ # @see http://www.last.fm/api/show/?service=118
101
+ def get_podcast( params )
102
+ LastFM.get( "artist.getPodcast", params )
103
+ end
104
+
105
+ # Get shouts for this artist.
106
+ #
107
+ # @option params [String, required unless :mbid] :artist the artist name
108
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
109
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
110
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
111
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
112
+ # @return [Array<LastFM::Shout>] collection of shouts
113
+ # @see http://www.last.fm/api/show/?service=397
114
+ def get_shouts( params )
115
+ xml = LastFM.get( "artist.getShouts", params )
116
+ xml.find('shouts/shout').map do |shout|
117
+ LastFM::Shout.from_xml( shout )
118
+ end
119
+ end
120
+
121
+ # Get all the artists similar to this artist.
122
+ #
123
+ # @option params [String, required unless :mbid] :artist the artist name
124
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
125
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
126
+ # @option params [Fixnum, optional] :limit limit the number of results to fetch
127
+ # @return [Array<LastFM::Artist>] list of similar artists
128
+ # @see http://www.last.fm/api/show/?service=119
129
+ def get_similar( params )
130
+ xml = LastFM.get( "artist.getSimilar", params )
131
+ xml.find('similarartists/artist').map do |artist|
132
+ LastFM::Artist.from_xml( artist )
133
+ end
134
+ end
135
+
136
+ # Get the tags applied by an individual user to an artist on Last.fm. If accessed as an authenticated service
137
+ # and you don't supply a user parameter then this service will return tags for the authenticated user.
138
+ #
139
+ # @option params [String, required unless :mbid] :artist the artist name
140
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
141
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
142
+ # @option params [String, optional] :user if called in non-authenticated mode you must specify the user to look up
143
+ # @see http://www.last.fm/api/show/?service=318
144
+ def get_tags( params )
145
+ secure = !params.include?(:user)
146
+ LastFM.requires_authentication if secure
147
+ LastFM.get( "artist.getTags", params, secure )
148
+ end
149
+
150
+ # Get the top albums for an artist, ordered by popularity.
151
+ #
152
+ # @option params [String, required unless :mbid] :artist the artist name
153
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
154
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
155
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
156
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
157
+ # @return [Array<LastFM::Album>] top albums, ordered by popularity
158
+ # @see http://www.last.fm/api/show/?service=287
159
+ def get_top_albums( params )
160
+ xml = LastFM.get( "artist.getTopAlbums", params )
161
+ xml.find('topalbums/album').map do |album|
162
+ LastFM::Album.from_xml( album )
163
+ end
164
+ end
165
+
166
+ # Get the top fans for an artist on Last.fm, based on listening data.
167
+ #
168
+ # @option params [String, required unless :mbid] :artist the artist name
169
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
170
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
171
+ # @see http://www.last.fm/api/show/?service=310
172
+ def get_top_fans( params )
173
+ LastFM.get( "artist.getTopFans", params )
174
+ end
175
+
176
+ # Get the top tags for an artist, ordered by popularity.
177
+ #
178
+ # @option params [String, required unless :mbid] :artist the artist name
179
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
180
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
181
+ # @return [Array<LastFM::Tag>] list of tags ordered by popularity
182
+ # @see http://www.last.fm/api/show/?service=288
183
+ def get_top_tags( params )
184
+ xml = LastFM.get( "artist.getTopTags", params )
185
+ xml.find('toptags/tag').map do |tag|
186
+ LastFM::Tag.from_xml( tag )
187
+ end
188
+ end
189
+
190
+ # Get the top tracks by an artist, ordered by popularity.
191
+ #
192
+ # @option params [String, required unless :mbid] :artist the artist name
193
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
194
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
195
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
196
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
197
+ # @return [Array<LastFM::Track>] top tracks, ordered by popularity
198
+ # @see http://www.last.fm/api/show/?service=277
199
+ def get_top_tracks( params )
200
+ xml = LastFM.get( "artist.getTopTracks", params )
201
+ xml.find('toptracks/track').map do |track|
202
+ LastFM::Track.from_xml( track )
203
+ end
204
+ end
205
+
206
+ # Remove a user's tag from an artist.
207
+ #
208
+ # @option params [String, required] :artist the artist name
209
+ # @option params [String, required] :tag a single user tag to remove from this artist
210
+ # @see http://www.last.fm/api/show/?service=315
211
+ def remove_tag( params )
212
+ LastFM.requires_authentication
213
+ LastFM.post( "artist.removeTag", params )
214
+ end
215
+
216
+ # Search for an artist by name. Returns artist matches sorted by relevance.
217
+ #
218
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
219
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
220
+ # @option params [String, required] :artist the artist name
221
+ # @return [Array<LastFM::Artist>] list of artists sorted by relevance
222
+ # @see http://www.last.fm/api/show/?service=272
223
+ def search( params )
224
+ xml = LastFM.get( "artist.search", params )
225
+ xml.find('results/artistmatches/artist').map do |artist|
226
+ LastFM::Artist.from_xml( artist )
227
+ end
228
+ end
229
+
230
+ # Share an artist with Last.fm users or other friends.
231
+ #
232
+ # @option params [String, required] :artist the artist name
233
+ # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
234
+ # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
235
+ # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
236
+ # @see http://www.last.fm/api/show/?service=306
237
+ def share( params )
238
+ LastFM.requires_authentication
239
+ LastFM.post( "artist.share", params )
240
+ end
241
+
242
+ # Shout in this artist's shoutbox.
243
+ #
244
+ # @option params [String, required] :artist name of the artist to shout on
245
+ # @option params [String, required] :message message to post to the shoutbox
246
+ # @see http://www.last.fm/api/show/?service=408
247
+ def shout( params )
248
+ LastFM.requires_authentication
249
+ LastFM.post( "artist.shout", params )
250
+ end
251
+
252
+ end
253
+
254
+ private
255
+
256
+ # Compensate for discrepancies between XML response and model attributes
257
+ alias :image= :images=
258
+ alias :bio= :wiki=
259
+
260
+ # node with nested listeners and playcount
261
+ def stats=(node)
262
+ node.find('*').each do |child|
263
+ send(:"#{child.name}=", child)
264
+ end
265
+ end
266
+
267
+ def parse_node(member, node)
268
+ case member
269
+ when :images
270
+ (self.images || {}).merge(node['size'].to_sym => node.content)
271
+ when :listeners, :playcount
272
+ node.content.to_i
273
+ when :name, :mbid, :url
274
+ node.content
275
+ when :similar
276
+ node.find('artist').map do |artist|
277
+ LastFM::Artist.from_xml(artist)
278
+ end
279
+ when :streamable
280
+ node.content == '1'
281
+ when :tags
282
+ node.find('tag').map do |tag|
283
+ LastFM::Tag.from_xml(tag)
284
+ end
285
+ when :wiki
286
+ LastFM::Wiki.from_xml(node)
287
+ end
288
+ end
289
+
290
+ end
291
+ end
@@ -0,0 +1,33 @@
1
+ module LastFM
2
+ class Auth
3
+ class << self
4
+
5
+ # Create a web service session for a user. Used for authenticating a user when the
6
+ # password can be inputted by the user. Only suitable for standalone mobile devices.
7
+ #
8
+ # @option params [String, required] :username last.fm username
9
+ # @option params [String, required] :auth_token md5 hash of the username + the password hash
10
+ # @see http://www.last.fm/api/show?service=266
11
+ def get_mobile_session( params )
12
+ LastFM.get( "auth.getMobileSession", params, :secure )
13
+ end
14
+
15
+ # Fetch a session key for a user. The third step in the authentication process.
16
+ #
17
+ # @option params [String, required] :token md5 hash returned by step 1 of the authentication process
18
+ # @see http://www.last.fm/api/show?service=125
19
+ def get_session( params )
20
+ LastFM.get( "auth.getSession", params, :secure )
21
+ end
22
+
23
+ # Fetch an unathorized request token for an API account. This is step 2 of
24
+ # the authentication process for desktop applications.
25
+ #
26
+ # @see http://www.last.fm/api/show?service=265
27
+ def get_token
28
+ LastFM.get( "auth.getToken", {}, :secure )
29
+ end
30
+
31
+ end
32
+ end
33
+ end