rscrobbler 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/lib/lastfm/album.rb +50 -112
  2. data/lib/lastfm/api/album.rb +140 -0
  3. data/lib/lastfm/api/artist.rb +243 -0
  4. data/lib/lastfm/api/auth.rb +35 -0
  5. data/lib/lastfm/api/chart.rb +63 -0
  6. data/lib/lastfm/api/event.rb +71 -0
  7. data/lib/lastfm/api/geo.rb +125 -0
  8. data/lib/lastfm/api/group.rb +69 -0
  9. data/lib/lastfm/api/library.rb +117 -0
  10. data/lib/lastfm/api/playlist.rb +40 -0
  11. data/lib/lastfm/api/radio.rb +41 -0
  12. data/lib/lastfm/api/tag.rb +120 -0
  13. data/lib/lastfm/api/tasteometer.rb +37 -0
  14. data/lib/lastfm/api/track.rb +272 -0
  15. data/lib/lastfm/api/user.rb +266 -0
  16. data/lib/lastfm/api/venue.rb +40 -0
  17. data/lib/lastfm/artist.rb +42 -204
  18. data/lib/lastfm/buylink.rb +34 -0
  19. data/lib/lastfm/event.rb +57 -66
  20. data/lib/lastfm/shout.rb +20 -0
  21. data/lib/lastfm/struct.rb +34 -0
  22. data/lib/lastfm/tag.rb +24 -89
  23. data/lib/lastfm/track.rb +51 -242
  24. data/lib/lastfm/venue.rb +21 -36
  25. data/lib/lastfm/wiki.rb +20 -0
  26. data/lib/rscrobbler.rb +24 -11
  27. data/test/test_album.rb +36 -0
  28. metadata +25 -45
  29. data/lib/lastfm/auth.rb +0 -35
  30. data/lib/lastfm/chart.rb +0 -63
  31. data/lib/lastfm/geo.rb +0 -125
  32. data/lib/lastfm/group.rb +0 -69
  33. data/lib/lastfm/library.rb +0 -117
  34. data/lib/lastfm/playlist.rb +0 -40
  35. data/lib/lastfm/radio.rb +0 -41
  36. data/lib/lastfm/tasteometer.rb +0 -37
  37. data/lib/lastfm/user.rb +0 -266
  38. data/test/unit/lib/lastfm/album_test.rb +0 -0
  39. data/test/unit/lib/lastfm/artist_test.rb +0 -0
  40. data/test/unit/lib/lastfm/auth_test.rb +0 -0
  41. data/test/unit/lib/lastfm/chart_test.rb +0 -0
  42. data/test/unit/lib/lastfm/event_test.rb +0 -0
  43. data/test/unit/lib/lastfm/geo_test.rb +0 -0
  44. data/test/unit/lib/lastfm/group_test.rb +0 -0
  45. data/test/unit/lib/lastfm/library_test.rb +0 -0
  46. data/test/unit/lib/lastfm/playlist_test.rb +0 -0
  47. data/test/unit/lib/lastfm/radio_test.rb +0 -0
  48. data/test/unit/lib/lastfm/tag_test.rb +0 -0
  49. data/test/unit/lib/lastfm/tasteometer_test.rb +0 -0
  50. data/test/unit/lib/lastfm/track_test.rb +0 -0
  51. data/test/unit/lib/lastfm/user_test.rb +0 -0
  52. data/test/unit/lib/lastfm/venue_test.rb +0 -0
  53. data/test/unit/lib/rscrobbler_test.rb +0 -0
data/lib/lastfm/album.rb CHANGED
@@ -1,117 +1,55 @@
1
1
  module LastFM
2
- class Album
3
- class << self
4
2
 
5
- TYPE = 'album'
6
-
7
- # Tag an album using a list of user supplied tags.
8
- #
9
- # @option params [String, required] :artist the artist name
10
- # @option params [String, required] :album the album name
11
- # @option params [Array, required] :tags up to 10 tags to apply to this album
12
- # @see http://www.last.fm/api/show?service=302
13
- def add_tags( params )
14
- LastFM.requires_authentication
15
- LastFM.post( "#{TYPE}.addTags", params )
16
- end
17
-
18
- # Get a list of buy links for an album.
19
- #
20
- # @option params [String, required unless :mbid] :artist the artist name
21
- # @option params [String, required unless :mbid] :album the album name
22
- # @option params [String, optional] :mbid the musicbrainz id for the album
23
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
24
- # @option params [String, optional] :country a country name, as defined by ISO 3166-1
25
- # @see http://www.last.fm/api/show?service=429
26
- def get_buylinks( params )
27
- LastFM.get( "#{TYPE}.getBuylinks", params )
28
- end
29
-
30
- # Get the metadata for an album.
31
- #
32
- # @option params [String, required unless :mbid] :artist the artist name
33
- # @option params [String, required unless :mbid] :album the album name
34
- # @option params [String, optional] :mbid the musicbrainz id for the album
35
- # @option params [String, optional] :lang the language to return the biography in, expressed as an ISO 639 alpha-2 code
36
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
37
- # @option params [String, optional] :username username whose playcount for this album is to be returned in the reponse
38
- # @see http://www.last.fm/api/show?service=290
39
- def get_info( params )
40
- LastFM.get( "#{TYPE}.getInfo", params )
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)
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)
41
51
  end
42
-
43
- # Get shouts for an album.
44
- #
45
- # @option params [String, required unless :mbid] :artist the artist name
46
- # @option params [String, required unless :mbid] :album the album name
47
- # @option params [String, optional] :mbid the musicbrainz id for the album
48
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
49
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
50
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
51
- # @see http://www.last.fm/api/show?service=450
52
- def get_shouts( params )
53
- LastFM.get( "#{TYPE}.getShouts", params )
54
- end
55
-
56
- # Get the tags applied by an individual user to an album.
57
- #
58
- # @option params [String, required unless :mbid] :artist the artist name
59
- # @option params [String, required unless :mbid] :album the album name
60
- # @option params [String, optional] :mbid the musicbrainz id for the album
61
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
62
- # @option params [String, optional] :user if called in non-authenticated mode you must specify the user to look up
63
- # @see http://www.last.fm/api/show?service=317
64
- def get_tags( params )
65
- secure = !params.include?(:user)
66
- LastFM.requires_authentication if secure
67
- LastFM.get( "#{TYPE}.getTags", params, secure )
68
- end
69
-
70
- # Get the top tags for an album, ordered by popularity.
71
- #
72
- # @option params [String, required unless :mbid] :artist the artist name
73
- # @option params [String, required unless :mbid] :album the album name
74
- # @option params [String, optional] :mbid the musicbrainz id for the album
75
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
76
- # @see http://www.last.fm/api/show?service=438
77
- def get_top_tags( params )
78
- LastFM.get( "#{TYPE}.getTopTags", params )
79
- end
80
-
81
- # Remove a user's tag from an album.
82
- #
83
- # @option params [String, required] :artist the artist name
84
- # @option params [String, required] :album the album name
85
- # @option params [String, required] :tag a single user tag to remove from this album
86
- # @see http://www.last.fm/api/show?service=314
87
- def remove_tag( params )
88
- LastFM.requires_authentication
89
- LastFM.post( "#{TYPE}.removeTag", params )
90
- end
91
-
92
- # Search for an album by name. Returns album matches sorted by relevance.
93
- #
94
- # @option params [String, required] :album the album name
95
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
96
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
97
- # @see http://www.last.fm/api/show?service=357
98
- def search( params )
99
- LastFM.get( "#{TYPE}.search", params )
100
- end
101
-
102
- # Share an album with one or more Last.fm users or other friends.
103
- #
104
- # @option params [String, required] :artist the artist name
105
- # @option params [String, required] :album the album name
106
- # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
107
- # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
108
- # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
109
- # @see http://www.last.fm/api/show?service=436
110
- def share( params )
111
- LastFM.requires_authentication
112
- LastFM.post( "#{TYPE}.share", params )
113
- end
114
-
115
52
  end
53
+
116
54
  end
117
- end
55
+ end
@@ -0,0 +1,140 @@
1
+ module LastFM
2
+ module Api
3
+ class Album
4
+ class << self
5
+
6
+ # Tag an album using a list of user supplied tags.
7
+ #
8
+ # @option params [String, required] :artist the artist name
9
+ # @option params [String, required] :album the album name
10
+ # @option params [Array, required] :tags up to 10 tags to apply to this album
11
+ # @see http://www.last.fm/api/show?service=302
12
+ def add_tags( params )
13
+ LastFM.requires_authentication
14
+ LastFM.post( "album.addTags", params )
15
+ end
16
+
17
+ # Get a list of buy links for an album.
18
+ #
19
+ # @option params [String, required unless :mbid] :artist the artist name
20
+ # @option params [String, required unless :mbid] :album the album name
21
+ # @option params [String, required] :country a country name, as defined by ISO 3166-1
22
+ # @option params [String, optional] :mbid the musicbrainz id for the album
23
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
24
+ # @return [Array<LastFM::Buylink>] collection of links where this album can be bought or downloaded
25
+ # @see http://www.last.fm/api/show?service=429
26
+ def get_buylinks( params )
27
+ xml = LastFM.get( "album.getBuylinks", params )
28
+ [:physical, :download].each_with_object([]) do |type, buylinks|
29
+ xml.find("affiliations/#{type}s/affiliation").each do |buylink|
30
+ buylinks << LastFM::Buylink.from_xml( buylink, :type => type )
31
+ end
32
+ end
33
+ end
34
+
35
+ # Get the metadata for an album.
36
+ #
37
+ # @option params [String, required unless :mbid] :artist the artist name
38
+ # @option params [String, required unless :mbid] :album the album name
39
+ # @option params [String, optional] :mbid the musicbrainz id for the album
40
+ # @option params [String, optional] :lang the language to return the biography in, expressed as an ISO 639 alpha-2 code
41
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
42
+ # @option params [String, optional] :username username whose playcount for this album is to be returned in the reponse
43
+ # @return [LastFM::Album] album constructed from the metadata contained in the response
44
+ # @see http://www.last.fm/api/show?service=290
45
+ def get_info( params )
46
+ xml = LastFM.get( "album.getInfo", params )
47
+ LastFM::Album.from_xml( xml )
48
+ end
49
+
50
+ # Get shouts 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 [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
56
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
57
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
58
+ # @return [Array<LastFM::Shout>] collection of shouts
59
+ # @see http://www.last.fm/api/show?service=450
60
+ def get_shouts( params )
61
+ xml = LastFM.get( "album.getShouts", params )
62
+ xml.find('shouts/shout').map do |shout|
63
+ LastFM::Shout.from_xml( shout )
64
+ end
65
+ end
66
+
67
+ # Get the tags applied by an individual user to an album.
68
+ #
69
+ # @option params [String, required unless :mbid] :artist the artist name
70
+ # @option params [String, required unless :mbid] :album the album name
71
+ # @option params [String, optional] :mbid the musicbrainz id for the album
72
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
73
+ # @option params [String, optional] :user if called in non-authenticated mode you must specify the user to look up
74
+ # @see http://www.last.fm/api/show?service=317
75
+ def get_tags( params )
76
+ secure = !params.include?(:user)
77
+ LastFM.requires_authentication if secure
78
+ xml = LastFM.get( "album.getTags", params, secure )
79
+ xml.find('tags/tag').map do |tag|
80
+ LastFM::Tag.from_xml( tag )
81
+ end
82
+ end
83
+
84
+ # Get the top tags for an album, ordered by popularity.
85
+ #
86
+ # @option params [String, required unless :mbid] :artist the artist name
87
+ # @option params [String, required unless :mbid] :album the album name
88
+ # @option params [String, optional] :mbid the musicbrainz id for the album
89
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
90
+ # @return [Array<LastFM::Tag>] list of tags sorted by popularity
91
+ # @see http://www.last.fm/api/show?service=438
92
+ def get_top_tags( params )
93
+ xml = LastFM.get( "album.getTopTags", params )
94
+ xml.find('toptags/tag').map do |tag|
95
+ LastFM::Tag.from_xml( tag )
96
+ end
97
+ end
98
+
99
+ # Remove a user's tag from an album.
100
+ #
101
+ # @option params [String, required] :artist the artist name
102
+ # @option params [String, required] :album the album name
103
+ # @option params [String, required] :tag a single user tag to remove from this album
104
+ # @see http://www.last.fm/api/show?service=314
105
+ def remove_tag( params )
106
+ LastFM.requires_authentication
107
+ LastFM.post( "album.removeTag", params )
108
+ end
109
+
110
+ # Search for an album by name. Returns album matches sorted by relevance.
111
+ #
112
+ # @option params [String, required] :album the album name
113
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
114
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
115
+ # @return [Array<LastFM::Album>] list of albums sorted by relevance
116
+ # @see http://www.last.fm/api/show?service=357
117
+ def search( params )
118
+ xml = LastFM.get( "album.search", params )
119
+ xml.find('results/albummatches/album').map do |album|
120
+ LastFM::Album.from_xml( album )
121
+ end
122
+ end
123
+
124
+ # Share an album with one or more Last.fm users or other friends.
125
+ #
126
+ # @option params [String, required] :artist the artist name
127
+ # @option params [String, required] :album the album name
128
+ # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
129
+ # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
130
+ # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
131
+ # @see http://www.last.fm/api/show?service=436
132
+ def share( params )
133
+ LastFM.requires_authentication
134
+ LastFM.post( "album.share", params )
135
+ end
136
+
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,243 @@
1
+ module LastFM
2
+ module Api
3
+ class Artist
4
+ class << self
5
+
6
+ # Tag an artist with one or more user supplied tags.
7
+ #
8
+ # @option params [String, required] :artist the artist name
9
+ # @option params [Array, required] :tags up to 10 tags to apply to this artist
10
+ # @see http://www.last.fm/api/show/?service=303
11
+ def add_tags( params )
12
+ LastFM.requires_authentication
13
+ LastFM.post( "artist.addTags", params )
14
+ end
15
+
16
+ # Check whether the supplied artist has a correction to a canonical artist.
17
+ #
18
+ # @option params [String, required] :artist the artist name
19
+ # @return [Array<LastFM::Artist>] list of suggestion corrections, in order of similarity
20
+ # @see http://www.last.fm/api/show/?service=446
21
+ def get_correction( params )
22
+ xml = LastFM.get( "artist.getCorrection", params )
23
+ xml.find('corrections/correction/artist').map do |correction|
24
+ LastFM::Artist.from_xml( correction )
25
+ end
26
+ end
27
+
28
+ # Get a list of upcoming events for this artist.
29
+ #
30
+ # @option params [String, required unless :mbid] :artist the artist name
31
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
32
+ # @option params [Boolean, optional] :festivalsonly whether only festivals should be returned, or all events
33
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
34
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
35
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
36
+ # @see http://www.last.fm/api/show/?service=117
37
+ def get_events( params )
38
+ xml = LastFM.get( "artist.getEvents", params )
39
+ xml.find('events/event').map do |event|
40
+ LastFM::Event.from_xml( event )
41
+ end
42
+ end
43
+
44
+ # Get images for this artist in a variety of sizes.
45
+ #
46
+ # @option params [String, required unless :mbid] :artist the artist name
47
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
48
+ # @option params [Symbol, optional] :order sort ordering can be either :popularity (default) or :dateadded
49
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
50
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
51
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
52
+ # @see http://www.last.fm/api/show/?service=407
53
+ def get_images( params )
54
+ LastFM.get( "artist.getImages", params )
55
+ end
56
+
57
+ # Get the metadata for an artist. Includes biography.
58
+ #
59
+ # @option params [String, required unless :mbid] :artist the artist name
60
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
61
+ # @option params [String, optional] :lang the language to return the biography in, expressed as an ISO 639 alpha-2 code
62
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
63
+ # @option params [String, optional] :username username whose playcount for this artist is to be returned in the reponse
64
+ # @return [LastFM::Artist] artist constructed from the metadata contained in the response
65
+ # @see http://www.last.fm/api/show/?service=267
66
+ def get_info( params )
67
+ xml = LastFM.get( "artist.getInfo", params )
68
+ LastFM::Artist.from_xml( xml )
69
+ end
70
+
71
+ # Get a paginated list of all the events this artist has played at in the past.
72
+ #
73
+ # @option params [String, required unless :mbid] :artist the artist name
74
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
75
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
76
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
77
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
78
+ # @see http://www.last.fm/api/show/?service=428
79
+ def get_past_events( params )
80
+ LastFM.get( "artist.getPastEvents", params )
81
+ end
82
+
83
+ # Get a podcast of free mp3s based on an artist.
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
+ # @see http://www.last.fm/api/show/?service=118
89
+ def get_podcast( params )
90
+ LastFM.get( "artist.getPodcast", params )
91
+ end
92
+
93
+ # Get shouts for this artist.
94
+ #
95
+ # @option params [String, required unless :mbid] :artist the artist name
96
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
97
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
98
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
99
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
100
+ # @return [Array<LastFM::Shout>] collection of shouts
101
+ # @see http://www.last.fm/api/show/?service=397
102
+ def get_shouts( params )
103
+ xml = LastFM.get( "artist.getShouts", params )
104
+ xml.find('shouts/shout').map do |shout|
105
+ LastFM::Shout.from_xml( shout )
106
+ end
107
+ end
108
+
109
+ # Get all the artists similar to this artist.
110
+ #
111
+ # @option params [String, required unless :mbid] :artist the artist name
112
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
113
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
114
+ # @option params [Fixnum, optional] :limit limit the number of results to fetch
115
+ # @return [Array<LastFM::Artist>] list of similar artists
116
+ # @see http://www.last.fm/api/show/?service=119
117
+ def get_similar( params )
118
+ xml = LastFM.get( "artist.getSimilar", params )
119
+ xml.find('similarartists/artist').map do |artist|
120
+ LastFM::Artist.from_xml( artist )
121
+ end
122
+ end
123
+
124
+ # Get the tags applied by an individual user to an artist on Last.fm. If accessed as an authenticated service
125
+ # and you don't supply a user parameter then this service will return tags for the authenticated user.
126
+ #
127
+ # @option params [String, required unless :mbid] :artist the artist name
128
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
129
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
130
+ # @option params [String, optional] :user if called in non-authenticated mode you must specify the user to look up
131
+ # @see http://www.last.fm/api/show/?service=318
132
+ def get_tags( params )
133
+ secure = !params.include?(:user)
134
+ LastFM.requires_authentication if secure
135
+ LastFM.get( "artist.getTags", params, secure )
136
+ end
137
+
138
+ # Get the top albums for an artist, ordered by popularity.
139
+ #
140
+ # @option params [String, required unless :mbid] :artist the artist name
141
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
142
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
143
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
144
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
145
+ # @return [Array<LastFM::Album>] top albums, ordered by popularity
146
+ # @see http://www.last.fm/api/show/?service=287
147
+ def get_top_albums( params )
148
+ xml = LastFM.get( "artist.getTopAlbums", params )
149
+ xml.find('topalbums/album').map do |album|
150
+ LastFM::Album.from_xml( album )
151
+ end
152
+ end
153
+
154
+ # Get the top fans for an artist on Last.fm, based on listening data.
155
+ #
156
+ # @option params [String, required unless :mbid] :artist the artist name
157
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
158
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
159
+ # @see http://www.last.fm/api/show/?service=310
160
+ def get_top_fans( params )
161
+ LastFM.get( "artist.getTopFans", params )
162
+ end
163
+
164
+ # Get the top tags for an artist, ordered by popularity.
165
+ #
166
+ # @option params [String, required unless :mbid] :artist the artist name
167
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
168
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
169
+ # @return [Array<LastFM::Tag>] list of tags ordered by popularity
170
+ # @see http://www.last.fm/api/show/?service=288
171
+ def get_top_tags( params )
172
+ xml = LastFM.get( "artist.getTopTags", params )
173
+ xml.find('toptags/tag').map do |tag|
174
+ LastFM::Tag.from_xml( tag )
175
+ end
176
+ end
177
+
178
+ # Get the top tracks by an artist, ordered by popularity.
179
+ #
180
+ # @option params [String, required unless :mbid] :artist the artist name
181
+ # @option params [String, optional] :mbid the musicbrainz id for the artist
182
+ # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
183
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
184
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
185
+ # @return [Array<LastFM::Track>] top tracks, ordered by popularity
186
+ # @see http://www.last.fm/api/show/?service=277
187
+ def get_top_tracks( params )
188
+ xml = LastFM.get( "artist.getTopTracks", params )
189
+ xml.find('toptracks/track').map do |track|
190
+ LastFM::Track.from_xml( track )
191
+ end
192
+ end
193
+
194
+ # Remove a user's tag from an artist.
195
+ #
196
+ # @option params [String, required] :artist the artist name
197
+ # @option params [String, required] :tag a single user tag to remove from this artist
198
+ # @see http://www.last.fm/api/show/?service=315
199
+ def remove_tag( params )
200
+ LastFM.requires_authentication
201
+ LastFM.post( "artist.removeTag", params )
202
+ end
203
+
204
+ # Search for an artist by name. Returns artist matches sorted by relevance.
205
+ #
206
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
207
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
208
+ # @option params [String, required] :artist the artist name
209
+ # @return [Array<LastFM::Artist>] list of artists sorted by relevance
210
+ # @see http://www.last.fm/api/show/?service=272
211
+ def search( params )
212
+ xml = LastFM.get( "artist.search", params )
213
+ xml.find('results/artistmatches/artist').map do |artist|
214
+ LastFM::Artist.from_xml( artist )
215
+ end
216
+ end
217
+
218
+ # Share an artist with Last.fm users or other friends.
219
+ #
220
+ # @option params [String, required] :artist the artist name
221
+ # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
222
+ # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
223
+ # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
224
+ # @see http://www.last.fm/api/show/?service=306
225
+ def share( params )
226
+ LastFM.requires_authentication
227
+ LastFM.post( "artist.share", params )
228
+ end
229
+
230
+ # Shout in this artist's shoutbox.
231
+ #
232
+ # @option params [String, required] :artist name of the artist to shout on
233
+ # @option params [String, required] :message message to post to the shoutbox
234
+ # @see http://www.last.fm/api/show/?service=408
235
+ def shout( params )
236
+ LastFM.requires_authentication
237
+ LastFM.post( "artist.shout", params )
238
+ end
239
+
240
+ end
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,35 @@
1
+ module LastFM
2
+ module Api
3
+ class Auth
4
+ class << self
5
+
6
+ # Create a web service session for a user. Used for authenticating a user when the
7
+ # password can be inputted by the user. Only suitable for standalone mobile devices.
8
+ #
9
+ # @option params [String, required] :username last.fm username
10
+ # @option params [String, required] :auth_token md5 hash of the username + the password hash
11
+ # @see http://www.last.fm/api/show?service=266
12
+ def get_mobile_session( params )
13
+ LastFM.get( "auth.getMobileSession", params, :secure )
14
+ end
15
+
16
+ # Fetch a session key for a user. The third step in the authentication process.
17
+ #
18
+ # @option params [String, required] :token md5 hash returned by step 1 of the authentication process
19
+ # @see http://www.last.fm/api/show?service=125
20
+ def get_session( params )
21
+ LastFM.get( "auth.getSession", params, :secure )
22
+ end
23
+
24
+ # Fetch an unathorized request token for an API account. This is step 2 of
25
+ # the authentication process for desktop applications.
26
+ #
27
+ # @see http://www.last.fm/api/show?service=265
28
+ def get_token
29
+ LastFM.get( "auth.getToken", {}, :secure )
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ module LastFM
2
+ module Api
3
+ class Chart
4
+ class << self
5
+
6
+ # Get the hyped artists chart
7
+ #
8
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
9
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
10
+ # @see http://www.last.fm/api/show?service=493
11
+ def get_hyped_artists( params )
12
+ LastFM.get( "chart.getHypedArtists", params )
13
+ end
14
+
15
+ # Get the hyped tracks chart
16
+ #
17
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
18
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
19
+ # @see http://www.last.fm/api/show?service=494
20
+ def get_hyped_tracks( params )
21
+ LastFM.get( "chart.getHypedTracks", params )
22
+ end
23
+
24
+ # Get the most loved tracks chart
25
+ #
26
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
27
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
28
+ # @see http://www.last.fm/api/show?service=495
29
+ def get_loved_tracks( params )
30
+ LastFM.get( "chart.getLovedTracks", params )
31
+ end
32
+
33
+ # Get the top artists chart
34
+ #
35
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
36
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
37
+ # @see http://www.last.fm/api/show?service=496
38
+ def get_top_artists( params )
39
+ LastFM.get( "chart.getTopArtists", params )
40
+ end
41
+
42
+ # Get the top tags chart
43
+ #
44
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
45
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
46
+ # @see http://www.last.fm/api/show?service=497
47
+ def get_top_tags( params )
48
+ LastFM.get( "chart.getTopTags", params )
49
+ end
50
+
51
+ # Get the top tracks chart
52
+ #
53
+ # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
54
+ # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
55
+ # @see http://www.last.fm/api/show?service=498
56
+ def get_top_tracks( params )
57
+ LastFM.get( "chart.getTopTracks", params )
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end