rscrobbler 0.1.0 → 0.2.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.
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/artist.rb CHANGED
@@ -1,210 +1,48 @@
1
1
  module LastFM
2
- class Artist
3
- class << self
4
2
 
5
- TYPE = 'artist'
6
-
7
- # Tag an artist with one or more user supplied tags.
8
- #
9
- # @option params [String, required] :artist the artist name
10
- # @option params [Array, required] :tags up to 10 tags to apply to this artist
11
- # @see http://www.last.fm/api/show/?service=303
12
- def add_tags( params )
13
- LastFM.requires_authentication
14
- LastFM.post( "#{TYPE}.addTags", params )
15
- end
16
-
17
- # Check whether the supplied artist has a correction to a canonical artist.
18
- #
19
- # @option params [String, required] :artist the artist name
20
- # @see http://www.last.fm/api/show/?service=446
21
- def get_correction( params )
22
- LastFM.get( "#{TYPE}.getCorrection", params )
23
- end
24
-
25
- # Get a list of upcoming events for this artist.
26
- #
27
- # @option params [String, required unless :mbid] :artist the artist name
28
- # @option params [String, optional] :mbid the musicbrainz id for the artist
29
- # @option params [Boolean, optional] :festivalsonly whether only festivals should be returned, or all events
30
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
31
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
32
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
33
- # @see http://www.last.fm/api/show/?service=117
34
- def get_events( params )
35
- LastFM.get( "#{TYPE}.getEvents", params )
36
- end
37
-
38
- # Get images for this artist in a variety of sizes.
39
- #
40
- # @option params [String, required unless :mbid] :artist the artist name
41
- # @option params [String, optional] :mbid the musicbrainz id for the artist
42
- # @option params [Symbol, optional] :order sort ordering can be either :popularity (default) or :dateadded
43
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
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=407
47
- def get_images( params )
48
- LastFM.get( "#{TYPE}.getImages", params )
49
- end
50
-
51
- # Get the metadata for an artist. Includes biography.
52
- #
53
- # @option params [String, required unless :mbid] :artist the artist name
54
- # @option params [String, optional] :mbid the musicbrainz id for the artist
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 artist is to be returned in the reponse
58
- # @see http://www.last.fm/api/show/?service=267
59
- def get_info( params )
60
- LastFM.get( "#{TYPE}.getInfo", params )
61
- end
62
-
63
- # Get a paginated list of all the events this artist has played at in the past.
64
- #
65
- # @option params [String, required unless :mbid] :artist the artist name
66
- # @option params [String, optional] :mbid the musicbrainz id for the artist
67
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
68
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
69
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
70
- # @see http://www.last.fm/api/show/?service=428
71
- def get_past_events( params )
72
- LastFM.get( "#{TYPE}.getPastEvents", params )
73
- end
74
-
75
- # Get a podcast of free mp3s based on an artist.
76
- #
77
- # @option params [String, required unless :mbid] :artist the artist name
78
- # @option params [String, optional] :mbid the musicbrainz id for the artist
79
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
80
- # @see http://www.last.fm/api/show/?service=118
81
- def get_podcast( params )
82
- LastFM.get( "#{TYPE}.getPodcast", params )
83
- end
84
-
85
- # Get shouts for this artist.
86
- #
87
- # @option params [String, required unless :mbid] :artist the artist name
88
- # @option params [String, optional] :mbid the musicbrainz id for the artist
89
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
90
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
91
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
92
- # @see http://www.last.fm/api/show/?service=397
93
- def get_shouts( params )
94
- LastFM.get( "#{TYPE}.getShouts", params )
95
- end
96
-
97
- # Get all the artists similar to this artist.
98
- #
99
- # @option params [String, required unless :mbid] :artist the artist name
100
- # @option params [String, optional] :mbid the musicbrainz id for the artist
101
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
102
- # @option params [Fixnum, optional] :limit limit the number of results to fetch
103
- # @see http://www.last.fm/api/show/?service=119
104
- def get_similar( params )
105
- LastFM.get( "#{TYPE}.getSimilar", params )
106
- end
107
-
108
- # Get the tags applied by an individual user to an artist on Last.fm. If accessed as an authenticated service
109
- # and you don't supply a user parameter then this service will return tags for the authenticated user.
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 [String, optional] :user if called in non-authenticated mode you must specify the user to look up
115
- # @see http://www.last.fm/api/show/?service=318
116
- def get_tags( params )
117
- secure = !params.include?(:user)
118
- LastFM.requires_authentication if secure
119
- LastFM.get( "#{TYPE}.getTags", params, secure )
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)
120
44
  end
121
-
122
- # Get the top albums for an artist, ordered by popularity.
123
- #
124
- # @option params [String, required unless :mbid] :artist the artist name
125
- # @option params [String, optional] :mbid the musicbrainz id for the artist
126
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
127
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
128
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
129
- # @see http://www.last.fm/api/show/?service=287
130
- def get_top_albums( params )
131
- LastFM.get( "#{TYPE}.getTopAlbums", params )
132
- end
133
-
134
- # Get the top fans for an artist on Last.fm, based on listening data.
135
- #
136
- # @option params [String, required unless :mbid] :artist the artist name
137
- # @option params [String, optional] :mbid the musicbrainz id for the artist
138
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
139
- # @see http://www.last.fm/api/show/?service=310
140
- def get_top_fans( params )
141
- LastFM.get( "#{TYPE}.getTopFans", params )
142
- end
143
-
144
- # Get the top tags for an artist, ordered by popularity.
145
- #
146
- # @option params [String, required unless :mbid] :artist the artist name
147
- # @option params [String, optional] :mbid the musicbrainz id for the artist
148
- # @option params [Boolean, optional] :autocorrect transform misspelled artist names into correct artist names to be returned in the response
149
- # @see http://www.last.fm/api/show/?service=288
150
- def get_top_tags( params )
151
- LastFM.get( "#{TYPE}.getTopTags", params )
152
- end
153
-
154
- # Get the top tracks by an artist, ordered by popularity.
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
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
160
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
161
- # @see http://www.last.fm/api/show/?service=277
162
- def get_top_tracks( params )
163
- LastFM.get( "#{TYPE}.getTopTracks", params )
164
- end
165
-
166
- # Remove a user's tag from an artist.
167
- #
168
- # @option params [String, required] :artist the artist name
169
- # @option params [String, required] :tag a single user tag to remove from this artist
170
- # @see http://www.last.fm/api/show/?service=315
171
- def remove_tag( params )
172
- LastFM.requires_authentication
173
- LastFM.post( "#{TYPE}.removeTag", params )
174
- end
175
-
176
- # Search for an artist by name. Returns artist matches sorted by relevance.
177
- #
178
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
179
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
180
- # @option params [String, required] :artist the artist name
181
- # @see http://www.last.fm/api/show/?service=272
182
- def search( params )
183
- LastFM.get( "#{TYPE}.search", params )
184
- end
185
-
186
- # Share an artist with Last.fm users or other friends.
187
- #
188
- # @option params [String, required] :artist the artist name
189
- # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
190
- # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
191
- # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
192
- # @see http://www.last.fm/api/show/?service=306
193
- def share( params )
194
- LastFM.requires_authentication
195
- LastFM.post( "#{TYPE}.share", params )
196
- end
197
-
198
- # Shout in this artist's shoutbox.
199
- #
200
- # @option params [String, required] :artist name of the artist to shout on
201
- # @option params [String, required] :message message to post to the shoutbox
202
- # @see http://www.last.fm/api/show/?service=408
203
- def shout( params )
204
- LastFM.requires_authentication
205
- LastFM.post( "#{TYPE}.shout", params )
206
- end
207
-
208
45
  end
46
+
209
47
  end
210
48
  end
@@ -0,0 +1,34 @@
1
+ module LastFM
2
+
3
+ # @attr [Symbol] type whether the link is for a physical purchase, or a download
4
+ # @attr [Hash] supplier
5
+ # @attr [Hash] price
6
+ # @attr [String] link
7
+ # @attr [Boolean] is_search
8
+ class Buylink < Struct.new(:type, :supplier, :price, :link, :is_search)
9
+
10
+ def update_from_node(node)
11
+ case node.name.to_sym
12
+ when :supplierName
13
+ self.supplier ||= {}
14
+ self.supplier[:name] = node.content
15
+ when :supplierIcon
16
+ self.supplier ||= {}
17
+ self.supplier[:icon] = node.content
18
+ when :price # nested price & currency
19
+ node.find('*').each{|child| self.update_from_node(child)}
20
+ when :amount
21
+ self.price ||= {}
22
+ self.price[:amount] = node.content.to_f
23
+ when :currency
24
+ self.price ||= {}
25
+ self.price[:currency] = node.content
26
+ when :buyLink
27
+ self.link = node.content
28
+ when :isSearch
29
+ self.is_search = (node.content == '1')
30
+ end
31
+ end
32
+
33
+ end
34
+ end
data/lib/lastfm/event.rb CHANGED
@@ -1,71 +1,62 @@
1
1
  module LastFM
2
- class Event
3
- class << self
4
2
 
5
- TYPE = 'event'
6
-
7
- # Set a user's attendance status for an event.
8
- #
9
- # @option params [Fixnum, required] :event numeric last.fm event id
10
- # @option params [Symbol, required] :status attendance status. accepted values are :attending, :maybe_attending, and :not_attending
11
- # @see http://www.last.fm/api/show?service=307
12
- def attend( params )
13
- LastFM.requires_authentication
14
- status_codes = { attending: 0, maybe_attending: 1, not_attending: 2 }
15
- params[:status] = status_codes[params[:status]] if params.include?(:status)
16
- LastFM.post( "#{TYPE}.attend", params )
17
- end
18
-
19
- # Get a list of attendees for an event.
20
- #
21
- # @option params [Fixnum, required] :event numeric last.fm event id
22
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
23
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
24
- # @see http://www.last.fm/api/show?service=391
25
- def get_attendees( params )
26
- LastFM.get( "#{TYPE}.getAttendees", params )
27
- end
28
-
29
- # Get the metadata for an event on Last.fm. Includes attendance and lineup information.
30
- #
31
- # @option params [Fixnum, required] :event numeric last.fm event id
32
- # @see http://www.last.fm/api/show?service=292
33
- def get_info( params )
34
- LastFM.get( "#{TYPE}.getInfo", params )
35
- end
36
-
37
- # Get shouts for an event.
38
- #
39
- # @option params [Fixnum, required] :event numeric last.fm event id
40
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
41
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
42
- # @see http://www.last.fm/api/show?service=399
43
- def get_shouts( params )
44
- LastFM.get( "#{TYPE}.getShouts", params )
3
+ # @attr [Fixnum] id
4
+ # @attr [String] title
5
+ # @attr [String] headliner
6
+ # @attr [Array<String>] artists
7
+ # @attr [LastFM::Venue] venue
8
+ # @attr [Time] start_date
9
+ # @attr [String] description
10
+ # @attr [Hash] images
11
+ # @attr [Fixnum] attendance
12
+ # @attr [Fixnum] reviews
13
+ # @attr [String] tag
14
+ # @attr [String] url Last.fm url for the event
15
+ # @attr [String] website Event website (different from Last.fm url)
16
+ # @attr [Boolean] cancelled
17
+ # @attr [Array<String>] tags
18
+ class Event < Struct.new(:id, :title, :headliner, :artists, :venue, :start_date, :description, :images, :attendance, :reviews, :tag, :url, :website, :cancelled, :tags)
19
+
20
+ def update_from_node(node)
21
+ case node.name.to_sym
22
+ when :id
23
+ self.id = node.content.to_i
24
+ when :title
25
+ self.title = node.content
26
+ when :artists # nested artists and headliner
27
+ node.find('*').each{|child| self.update_from_node(child)}
28
+ when :artist
29
+ self.artists ||= []
30
+ self.artists << node.content
31
+ when :headliner
32
+ self.headliner = node.content
33
+ when :venue
34
+ self.venue = LastFM::Venue.from_xml( node )
35
+ when :startDate
36
+ self.start_date = Time.parse(node.content)
37
+ when :description
38
+ self.description = node.content
39
+ when :image
40
+ self.images ||= {}
41
+ self.images.merge!({node['size'].to_sym => node.content})
42
+ when :attendance
43
+ self.attendance = node.content.to_i
44
+ when :reviews
45
+ self.reviews = node.content.to_i
46
+ when :tag
47
+ self.tag = node.content
48
+ when :url
49
+ self.url = node.content
50
+ when :website
51
+ self.website = node.content
52
+ when :tickets
53
+ # ???
54
+ when :cancelled
55
+ self.cancelled = (node.content == '1')
56
+ when :tags
57
+ self.tags = node.find('*').each{|tag| tag.content}
45
58
  end
46
-
47
- # Share an event with one or more Last.fm users or other friends.
48
- #
49
- # @option params [Fixnum, required] :event numeric last.fm event id
50
- # @option params [Array, required] :recipient a list of email addresses or Last.fm usernames. maximum is 10
51
- # @option params [String, optional] :message an optional message to send. if not supplied a default message will be used
52
- # @option params [Boolean, optional] :public optionally show in the sharing users activity feed. defaults to false
53
- # @see http://www.last.fm/api/show?service=350
54
- def share( params )
55
- LastFM.requires_authentication
56
- LastFM.post( "#{TYPE}.share", params )
57
- end
58
-
59
- # Shout in an event's shoutbox.
60
- #
61
- # @option params [Fixnum, required] :event numeric last.fm event id
62
- # @option params [String, required] :message message to post to the shoutbox
63
- # @see http://www.last.fm/api/show?service=409
64
- def shout( params )
65
- LastFM.requires_authentication
66
- LastFM.post( "#{TYPE}.shout", params )
67
- end
68
-
69
59
  end
60
+
70
61
  end
71
- end
62
+ end
@@ -0,0 +1,20 @@
1
+ module LastFM
2
+
3
+ # @attr [String] author
4
+ # @attr [String] body
5
+ # @attr [Time] date
6
+ class Shout < Struct.new(:author, :body, :date)
7
+
8
+ def update_from_node(node)
9
+ case node.name.to_sym
10
+ when :author
11
+ self.author = node.content
12
+ when :body
13
+ self.body = node.content
14
+ when :date
15
+ self.date = Time.parse(node.content)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module LastFM
2
+
3
+ # Prodives modifications to Ruby's Struct class for use within the LastFM module space.
4
+ # Must be called 'Struct' to play nice with YARD's @attr documentation.
5
+ class Struct < Struct
6
+
7
+ # Override Struct's initialize method to accept a hash of members instead.
8
+ def initialize(h={})
9
+ members.each{|m| self[m] = h[m.to_sym]}
10
+ end
11
+
12
+ # Get the Last.fm package name for a Ruby class
13
+ #
14
+ # @return [String] the Last.fm package name
15
+ def self.package
16
+ self.to_s.downcase.split('::').last
17
+ end
18
+
19
+ # Construct a LastFM::Struct object from XML, using each inheritor's attr_from_node
20
+ # method to determine how to manipulate individual attributes.
21
+ #
22
+ # @param [LibXML::XML::Document] xml XML obtained from a Last.fm API call
23
+ # @param [Hash] initial_attributes Attributes to set before parsing the XML
24
+ # @return [LastFM::Struct] object contructed from attributes contained in XML
25
+ def self.from_xml(xml, initial_attributes={})
26
+ raise NotImplementedError unless self.method_defined?(:update_from_node)
27
+ xml = xml.find_first(self.package) if xml.is_a?(LibXML::XML::Document)
28
+ model = self.new(initial_attributes)
29
+ xml.find('*').each{|child| model.update_from_node(child)}
30
+ model
31
+ end
32
+
33
+ end
34
+ end
data/lib/lastfm/tag.rb CHANGED
@@ -1,94 +1,29 @@
1
1
  module LastFM
2
- class Tag
3
- class << self
4
2
 
5
- TYPE = 'tag'
6
-
7
- # Get the metadata for a tag.
8
- #
9
- # @option params [String, required] :tag the tag name
10
- # @option params [String, optinoal] :lang the language to return the summary in, expressed as an ISO 639 alpha-2 code
11
- # @see http://www.last.fm/api/show?service=452
12
- def get_info( params )
13
- LastFM.get( "#{TYPE}.getInfo", params )
14
- end
15
-
16
- # Search for tags similar to this one. Returns tags ranked by similarity, based on listening data.
17
- #
18
- # @option params [String, required] tag the tag name
19
- # @see http://www.last.fm/api/show?service=311
20
- def get_similar( params )
21
- LastFM.get( "#{TYPE}.getSimilar", params )
22
- end
23
-
24
- # Get the top albums tagged with a tag, ordered by tag count.
25
- #
26
- # @option params [String, required] :tag the tag name
27
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
28
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
29
- # @see http://www.last.fm/api/show?service=283
30
- def get_top_albums( params )
31
- LastFM.get( "#{TYPE}.getTopAlbums", params )
3
+ # @attr [String] name
4
+ # @attr [Fixnum] count
5
+ # @attr [String] url
6
+ # @attr [Fixnum] reach
7
+ # @attr [Boolean] streamable
8
+ # @attr [LastFM::Wiki] wiki
9
+ class Tag < Struct.new(:name, :count, :url, :reach, :streamable, :wiki)
10
+
11
+ def update_from_node(node)
12
+ case node.name.to_sym
13
+ when :name
14
+ self.name = node.content
15
+ when :url
16
+ self.url = node.content
17
+ when :reach
18
+ self.reach = node.content.to_i
19
+ when :count, :taggings
20
+ self.count = node.content.to_i
21
+ when :streamable
22
+ self.streamable = (node.content == '1')
23
+ when :wiki
24
+ self.wiki = LastFM::Wiki.from_xml(node)
32
25
  end
33
-
34
- # Get the top artists tagged with a tag, ordered by tag count.
35
- #
36
- # @option params [String, required] :tag the tag name
37
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
38
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
39
- # @see http://www.last.fm/api/show?service=284
40
- def get_top_artists( params )
41
- LastFM.get( "#{TYPE}.getTopArtists", params )
42
- end
43
-
44
- # Fetches the top global tags on Last.fm, sorted by popularity (number of times used).
45
- #
46
- # @see http://www.last.fm/api/show?service=276
47
- def get_top_tags
48
- LastFM.get( "#{TYPE}.getTopTags" )
49
- end
50
-
51
- # Get the top tracks tagged with a tag, ordered by tag count.
52
- #
53
- # @option params [String, required] :tag the tag name
54
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
55
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
56
- # @see http://www.last.fm/api/show?service=285
57
- def get_top_tracks( params )
58
- LastFM.get( "#{TYPE}.getTopTracks", params )
59
- end
60
-
61
- # Get an artist chart for a tag, for a given date range. If no date range is
62
- # supplied, it will return the most recent artist chart for this tag.
63
- #
64
- # @option params [String, required] :tag the tag name
65
- # @option params [String, optional] :from date at which the chart should start from (see: Tag.get_weekly_chart_list)
66
- # @option params [String, optional] :to date at which the chart should end on (see: Tag.get_weekly_chart_list)
67
- # @option params [Fixnum, optional] :limit the number of results to fetch. defaults to 50
68
- # @see http://www.last.fm/api/show?service=358
69
- def get_weekly_artist_chart( params )
70
- LastFM.get( "#{TYPE}.getWeeklyArtistChart", params )
71
- end
72
-
73
- # Get a list of available charts for this tag, expressed as date
74
- # ranges which can be sent to the chart services.
75
- #
76
- # @option params [String, required] :tag the tag name
77
- # @see http://www.last.fm/api/show?service=359
78
- def get_weekly_chart_list( params )
79
- LastFM.get( "#{TYPE}.getWeeklyChartList", params )
80
- end
81
-
82
- # Search for a tag by name. Returns matches sorted by relevance.
83
- #
84
- # @option params [String, required] :tag the tag name
85
- # @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
86
- # @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
87
- # @see http://www.last.fm/api/show?service=273
88
- def search( params )
89
- LastFM.get( "#{TYPE}.search", params )
90
- end
91
-
92
26
  end
93
- end
27
+
28
+ end
94
29
  end