shortwave 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/.document +5 -0
  2. data/.gitignore +10 -0
  3. data/.gitmodules +3 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +74 -0
  6. data/Rakefile +133 -0
  7. data/VERSION +1 -0
  8. data/lib/shortwave.rb +12 -0
  9. data/lib/shortwave/authentication.rb +107 -0
  10. data/lib/shortwave/facade.rb +3 -0
  11. data/lib/shortwave/facade/build/facade_builder.rb +199 -0
  12. data/lib/shortwave/facade/build/facade_template.erb +17 -0
  13. data/lib/shortwave/facade/lastfm.rb +878 -0
  14. data/lib/shortwave/facade/remote.rb +86 -0
  15. data/lib/shortwave/model/album.rb +33 -0
  16. data/lib/shortwave/model/artist.rb +62 -0
  17. data/lib/shortwave/model/base_model.rb +112 -0
  18. data/lib/shortwave/model/chart_dates.rb +15 -0
  19. data/lib/shortwave/model/comparison.rb +15 -0
  20. data/lib/shortwave/model/event.rb +55 -0
  21. data/lib/shortwave/model/group.rb +26 -0
  22. data/lib/shortwave/model/location.rb +45 -0
  23. data/lib/shortwave/model/playlist.rb +36 -0
  24. data/lib/shortwave/model/shout.rb +21 -0
  25. data/lib/shortwave/model/tag.rb +47 -0
  26. data/lib/shortwave/model/track.rb +71 -0
  27. data/lib/shortwave/model/user.rb +70 -0
  28. data/lib/shortwave/model/venue.rb +37 -0
  29. data/lib/shortwave/model/weekly_charts.rb +31 -0
  30. data/lib/shortwave/providers.rb +161 -0
  31. data/shortwave.gemspec +178 -0
  32. data/test/authentication_test.rb +64 -0
  33. data/test/build/build_test.rb +25 -0
  34. data/test/build/data/intro.yml +2 -0
  35. data/test/build/data/screens/album_addTags.html +1238 -0
  36. data/test/build/data/screens/intro_truncated.html +426 -0
  37. data/test/build/data/screens/tasteometer_compare.html +1274 -0
  38. data/test/build/data/screens/user_getLovedTracks.html +1278 -0
  39. data/test/build/data/screens/venue_search.html +1261 -0
  40. data/test/build/facade_builder_test.rb +23 -0
  41. data/test/build/parameter_test.rb +43 -0
  42. data/test/build/remote_method_test.rb +47 -0
  43. data/test/build/ruby_class_test.rb +12 -0
  44. data/test/build/ruby_method_test.rb +137 -0
  45. data/test/helper.rb +35 -0
  46. data/test/model/album_test.rb +62 -0
  47. data/test/model/artist_test.rb +103 -0
  48. data/test/model/chart_dates_test.rb +11 -0
  49. data/test/model/comparison_test.rb +18 -0
  50. data/test/model/data/album_info.xml +38 -0
  51. data/test/model/data/album_search.xml +210 -0
  52. data/test/model/data/artist_info.xml +58 -0
  53. data/test/model/data/artist_search.xml +109 -0
  54. data/test/model/data/artist_shouts.xml +546 -0
  55. data/test/model/data/artist_top_fans.xml +405 -0
  56. data/test/model/data/event_info.xml +47 -0
  57. data/test/model/data/group_members.xml +242 -0
  58. data/test/model/data/group_weekly_album_chart.xml +1754 -0
  59. data/test/model/data/group_weekly_artist_chart.xml +604 -0
  60. data/test/model/data/group_weekly_track_chart.xml +1005 -0
  61. data/test/model/data/location_events.xml +383 -0
  62. data/test/model/data/ok.xml +2 -0
  63. data/test/model/data/playlist_fetch.xml +227 -0
  64. data/test/model/data/tag_search.xml +110 -0
  65. data/test/model/data/tag_similar.xml +254 -0
  66. data/test/model/data/tag_top_albums.xml +805 -0
  67. data/test/model/data/tag_top_artists.xml +605 -0
  68. data/test/model/data/tag_top_tags.xml +1254 -0
  69. data/test/model/data/tag_top_tracks.xml +843 -0
  70. data/test/model/data/tag_weekly_chart_list.xml +57 -0
  71. data/test/model/data/tasteometer_compare.xml +54 -0
  72. data/test/model/data/track_info.xml +53 -0
  73. data/test/model/data/track_search.xml +195 -0
  74. data/test/model/data/user_chartlist.xml +90 -0
  75. data/test/model/data/user_info.xml +16 -0
  76. data/test/model/data/user_neighbours.xml +484 -0
  77. data/test/model/data/user_playlists.xml +17 -0
  78. data/test/model/data/user_recent_tracks.xml +124 -0
  79. data/test/model/data/user_recommended_artists.xml +454 -0
  80. data/test/model/data/user_shouts.xml +9 -0
  81. data/test/model/data/user_weekly_artist_chart.xml +478 -0
  82. data/test/model/data/venue_events.xml +556 -0
  83. data/test/model/data/venue_past_events.xml +1778 -0
  84. data/test/model/data/venue_search.xml +355 -0
  85. data/test/model/event_test.rb +63 -0
  86. data/test/model/group_test.rb +45 -0
  87. data/test/model/location_test.rb +25 -0
  88. data/test/model/playlist_test.rb +51 -0
  89. data/test/model/shout_test.rb +23 -0
  90. data/test/model/tag_test.rb +39 -0
  91. data/test/model/track_test.rb +67 -0
  92. data/test/model/user_test.rb +125 -0
  93. data/test/model/venue_test.rb +60 -0
  94. data/test/provider/album_provider_test.rb +26 -0
  95. data/test/provider/artist_provider_test.rb +25 -0
  96. data/test/provider/group_provider_test.rb +9 -0
  97. data/test/provider/location_provider_test.rb +9 -0
  98. data/test/provider/playlist_provider_test.rb +12 -0
  99. data/test/provider/tag_provider_test.rb +24 -0
  100. data/test/provider/track_provider_test.rb +26 -0
  101. data/test/provider/user_provider_test.rb +11 -0
  102. data/test/provider/venue_provider_test.rb +15 -0
  103. data/test/provider_test_helper.rb +27 -0
  104. data/test/remote_test.rb +26 -0
  105. metadata +209 -0
@@ -0,0 +1,17 @@
1
+ <%# This comment is for the output, not this file. -%>
2
+ # This file is autogenerated - don't edit!
3
+
4
+ module Shortwave
5
+ module Facade
6
+ <% for klass in klasses %>
7
+ class <%= klass.name %> < Remote
8
+ <% for method in klass.methods %>
9
+ <%= method.comment.join("\n ") %>
10
+ def <%= method.signature %>
11
+ <%= method.body.join("\n ") %>
12
+ end
13
+ <% end %>
14
+ end
15
+ <% end %>
16
+ end
17
+ end
@@ -0,0 +1,878 @@
1
+
2
+ # This file is autogenerated - don't edit!
3
+
4
+ module Shortwave
5
+ module Facade
6
+
7
+ class Track < Remote
8
+
9
+ # Love a track for a user profile. This needs to be supplemented with a scrobbling submission containing the 'love' rating (see the audioscrobbler API).
10
+ #
11
+ # +track+:: A track name (utf8 encoded)
12
+ # +artist+:: An artist name (utf8 encoded)
13
+ def love(track, artist)
14
+ post(:session, {:method => "track.love", :track => track, :artist => artist})
15
+ end
16
+
17
+ # Remove a user's tag from a track.
18
+ #
19
+ # +artist+:: The artist name in question
20
+ # +track+:: The track name in question
21
+ # +tags+:: A single user tag to remove from this track.
22
+ def remove_tag(artist, track, tags)
23
+ post(:session, {:method => "track.removeTag", :artist => artist, :track => track, :tags => tags})
24
+ end
25
+
26
+ # Search for a track by track name. Returns track matches sorted by relevance.
27
+ #
28
+ # +track+:: The track name in question.
29
+ #
30
+ # <b>Options</b>
31
+ # +limit+:: Limit the number of tracks returned at one time. Default (maximum) is 30.
32
+ # +page+:: Scan into the results by specifying a page number. Defaults to first page.
33
+ # +artist+:: Narrow your search by specifying an artist.
34
+ def search(track, options={})
35
+ get(:standard, {:method => "track.search", :track => track}.merge(options))
36
+ end
37
+
38
+ # Tag an album using a list of user supplied tags.
39
+ #
40
+ # +artist+:: The artist name in question
41
+ # +track+:: The track name in question
42
+ # +tags+:: A comma delimited list of user supplied tags to apply to this track. Accepts a maximum of 10 tags.
43
+ def add_tags(artist, track, tags)
44
+ post(:session, {:method => "track.addTags", :artist => artist, :track => track, :tags => tags})
45
+ end
46
+
47
+ # Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.
48
+ #
49
+ # <b>Options</b>
50
+ # +artist+:: The artist name in question
51
+ # +track+:: The track name in question
52
+ # +mbid+:: The musicbrainz id for the track
53
+ def info(options={})
54
+ get(:standard, {:method => "track.getInfo"}.merge(options))
55
+ end
56
+
57
+ # Get the tags applied by an individual user to a track on Last.fm.
58
+ #
59
+ # +artist+:: The artist name in question
60
+ # +track+:: The track name in question
61
+ def tags(artist, track)
62
+ get(:session, {:method => "track.getTags", :artist => artist, :track => track})
63
+ end
64
+
65
+ # Get the top fans for this track on Last.fm, based on listening data. Supply either track & artist name or musicbrainz id.
66
+ #
67
+ # <b>Options</b>
68
+ # +track+:: The track name in question
69
+ # +artist+:: The artist name in question
70
+ # +mbid+:: The musicbrainz id for the track
71
+ def top_fans(options={})
72
+ get(:standard, {:method => "track.getTopFans"}.merge(options))
73
+ end
74
+
75
+ # Ban a track for a given user profile. This needs to be supplemented with a scrobbling submission containing the 'ban' rating (see the audioscrobbler API).
76
+ #
77
+ # +track+:: A track name (utf8 encoded)
78
+ # +artist+:: An artist name (utf8 encoded)
79
+ def ban(track, artist)
80
+ post(:session, {:method => "track.ban", :track => track, :artist => artist})
81
+ end
82
+
83
+ # Get the top tags for this track on Last.fm, ordered by tag count. Supply either track & artist name or mbid.
84
+ #
85
+ # <b>Options</b>
86
+ # +track+:: The track name in question
87
+ # +artist+:: The artist name in question
88
+ # +mbid+:: The musicbrainz id for the track
89
+ def top_tags(options={})
90
+ get(:standard, {:method => "track.getTopTags"}.merge(options))
91
+ end
92
+
93
+ # Get the similar tracks for this track on Last.fm, based on listening data.
94
+ #
95
+ # <b>Options</b>
96
+ # +track+:: The track name in question
97
+ # +artist+:: The artist name in question
98
+ # +mbid+:: The musicbrainz id for the track
99
+ def similar(options={})
100
+ get(:standard, {:method => "track.getSimilar"}.merge(options))
101
+ end
102
+
103
+ # Share a track twith one or more Last.fm users or other friends.
104
+ #
105
+ # +artist+:: An artist name.
106
+ # +recipient+:: Email Address | Last.fm Username - A comma delimited list of email addresses or Last.fm usernames. Maximum is 10.
107
+ # +track+:: A track name.
108
+ #
109
+ # <b>Options</b>
110
+ # +message+:: An optional message to send with the recommendation. If not supplied a default message will be used.
111
+ def share(artist, recipient, track, options={})
112
+ post(:session, {:method => "track.share", :artist => artist, :recipient => recipient, :track => track}.merge(options))
113
+ end
114
+
115
+ end
116
+
117
+ class User < Remote
118
+
119
+ # Get the last 50 tracks loved by a user.
120
+ #
121
+ # +user+:: The user name to fetch the loved tracks for.
122
+ def loved_tracks(user)
123
+ get(:standard, {:method => "user.getLovedTracks", :user => user})
124
+ end
125
+
126
+ # Get a list of a user's neighbours on Last.fm.
127
+ #
128
+ # +user+:: The last.fm username to fetch the neighbours of.
129
+ #
130
+ # <b>Options</b>
131
+ # +limit+:: An integer used to limit the number of neighbours returned.
132
+ def neighbours(user, options={})
133
+ get(:standard, {:method => "user.getNeighbours", :user => user}.merge(options))
134
+ end
135
+
136
+ # Get a list of the recent tracks listened to by this user. Indicates now playing track if the user is currently listening.
137
+ #
138
+ # +user+:: The last.fm username to fetch the recent tracks of.
139
+ #
140
+ # <b>Options</b>
141
+ # +limit+:: An integer used to limit the number of tracks returned.
142
+ def recent_tracks(user, options={})
143
+ get(:standard, {:method => "user.getRecentTracks", :user => user}.merge(options))
144
+ end
145
+
146
+ # Shout on this user's shoutbox
147
+ #
148
+ # +user+:: The name of the user to shout on.
149
+ # +message+:: The message to post to the shoutbox.
150
+ def shout(user, message)
151
+ post(:session, {:method => "user.shout", :user => user, :message => message})
152
+ end
153
+
154
+ # Get a list of upcoming events that this user is attending. Easily integratable into calendars, using the ical standard (see 'more formats' section below).
155
+ #
156
+ # +user+:: The user to fetch the events for.
157
+ def events(user)
158
+ get(:standard, {:method => "user.getEvents", :user => user})
159
+ end
160
+
161
+ # Get the top tracks listened to by a user. You can stipulate a time period. Sends the overall chart by default.
162
+ #
163
+ # +user+:: The user name to fetch top tracks for.
164
+ #
165
+ # <b>Options</b>
166
+ # +period+:: overall | 3month | 6month | 12month - The time period over which to retrieve top tracks for.
167
+ def top_tracks(user, options={})
168
+ get(:standard, {:method => "user.getTopTracks", :user => user}.merge(options))
169
+ end
170
+
171
+ # Get information about a user profile.
172
+ def info()
173
+ get(:session, {:method => "user.getInfo"})
174
+ end
175
+
176
+ # Get a paginated list of all events recommended to a user by Last.fm, based on their listening profile.
177
+ #
178
+ # <b>Options</b>
179
+ # +page+:: The page number to scan to.
180
+ # +limit+:: The number of events to return per page.
181
+ def recommended_events(options={})
182
+ get(:session, {:method => "user.getRecommendedEvents"}.merge(options))
183
+ end
184
+
185
+ # Get the top artists listened to by a user. You can stipulate a time period. Sends the overall chart by default.
186
+ #
187
+ # +user+:: The user name to fetch top artists for.
188
+ #
189
+ # <b>Options</b>
190
+ # +period+:: overall | 3month | 6month | 12month - The time period over which to retrieve top artists for.
191
+ def top_artists(user, options={})
192
+ get(:standard, {:method => "user.getTopArtists", :user => user}.merge(options))
193
+ end
194
+
195
+ # Get a list of the user's friends on Last.fm.
196
+ #
197
+ # +user+:: The last.fm username to fetch the friends of.
198
+ #
199
+ # <b>Options</b>
200
+ # +recenttracks+:: Whether or not to include information about friends' recent listening in the response.
201
+ # +limit+:: An integer used to limit the number of friends returned per page. The default is 50.
202
+ # +page+:: The page number to fetch.
203
+ def friends(user, options={})
204
+ get(:standard, {:method => "user.getFriends", :user => user}.merge(options))
205
+ end
206
+
207
+ # Get shouts for this user. Also available as an rss feed.
208
+ #
209
+ # +user+:: The username to fetch shouts for
210
+ def shouts(user)
211
+ get(:standard, {:method => "user.getShouts", :user => user})
212
+ end
213
+
214
+ # Get an album chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent album chart for this user.
215
+ #
216
+ # +user+:: The last.fm username to fetch the charts of.
217
+ #
218
+ # <b>Options</b>
219
+ # +from+:: The date at which the chart should start from. See User.getChartsList for more.
220
+ # +to+:: The date at which the chart should end on. See User.getChartsList for more.
221
+ def weekly_album_chart(user, options={})
222
+ get(:standard, {:method => "user.getWeeklyAlbumChart", :user => user}.merge(options))
223
+ end
224
+
225
+ # Get an artist chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent artist chart for this user.
226
+ #
227
+ # +user+:: The last.fm username to fetch the charts of.
228
+ #
229
+ # <b>Options</b>
230
+ # +from+:: The date at which the chart should start from. See User.getWeeklyChartList for more.
231
+ # +to+:: The date at which the chart should end on. See User.getWeeklyChartList for more.
232
+ def weekly_artist_chart(user, options={})
233
+ get(:standard, {:method => "user.getWeeklyArtistChart", :user => user}.merge(options))
234
+ end
235
+
236
+ # Get a list of a user's playlists on Last.fm.
237
+ #
238
+ # +user+:: The last.fm username to fetch the playlists of.
239
+ def playlists(user)
240
+ get(:standard, {:method => "user.getPlaylists", :user => user})
241
+ end
242
+
243
+ # Get a paginated list of all events a user has attended in the past.
244
+ #
245
+ # +user+:: The username to fetch the events for.
246
+ #
247
+ # <b>Options</b>
248
+ # +page+:: The page number to scan to.
249
+ # +limit+:: The number of events to return per page.
250
+ def past_events(user, options={})
251
+ get(:standard, {:method => "user.getPastEvents", :user => user}.merge(options))
252
+ end
253
+
254
+ # Get Last.fm artist recommendations for a user
255
+ def recommended_artists()
256
+ get(:session, {:method => "user.getRecommendedArtists"})
257
+ end
258
+
259
+ # Get the top albums listened to by a user. You can stipulate a time period. Sends the overall chart by default.
260
+ #
261
+ # +user+:: The user name to fetch top albums for.
262
+ #
263
+ # <b>Options</b>
264
+ # +period+:: overall | 3month | 6month | 12month - The time period over which to retrieve top albums for.
265
+ def top_albums(user, options={})
266
+ get(:standard, {:method => "user.getTopAlbums", :user => user}.merge(options))
267
+ end
268
+
269
+ # Get a list of available charts for this user, expressed as date ranges which can be sent to the chart services.
270
+ #
271
+ # +user+:: The last.fm username to fetch the charts list for.
272
+ def weekly_chart_list(user)
273
+ get(:standard, {:method => "user.getWeeklyChartList", :user => user})
274
+ end
275
+
276
+ # Get the top tags used by this user.
277
+ #
278
+ # +user+:: The user name
279
+ #
280
+ # <b>Options</b>
281
+ # +limit+:: Limit the number of tags returned
282
+ def top_tags(user, options={})
283
+ get(:standard, {:method => "user.getTopTags", :user => user}.merge(options))
284
+ end
285
+
286
+ # Get a track chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent track chart for this user.
287
+ #
288
+ # +user+:: The last.fm username to fetch the charts of.
289
+ #
290
+ # <b>Options</b>
291
+ # +from+:: The date at which the chart should start from. See User.getWeeklyChartList for more.
292
+ # +to+:: The date at which the chart should end on. See User.getWeeklyChartList for more.
293
+ def weekly_track_chart(user, options={})
294
+ get(:standard, {:method => "user.getWeeklyTrackChart", :user => user}.merge(options))
295
+ end
296
+
297
+ end
298
+
299
+ class Group < Remote
300
+
301
+ # Get a list of members for this group.
302
+ #
303
+ # +group+:: The group name to fetch the members of.
304
+ def members(group)
305
+ get(:standard, {:method => "group.getMembers", :group => group})
306
+ end
307
+
308
+ # Get a list of available charts for this group, expressed as date ranges which can be sent to the chart services.
309
+ #
310
+ # +group+:: The last.fm group name to fetch the charts list for.
311
+ def weekly_chart_list(group)
312
+ get(:standard, {:method => "group.getWeeklyChartList", :group => group})
313
+ end
314
+
315
+ # Get an album chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group.
316
+ #
317
+ # +group+:: Group name
318
+ #
319
+ # <b>Options</b>
320
+ # +from+:: The date at which the chart should start from. See Group.getWeeklyChartList for more.
321
+ # +to+:: The date at which the chart should end on. See Group.getWeeklyChartList for more.
322
+ def weekly_album_chart(group, options={})
323
+ get(:standard, {:method => "group.getWeeklyAlbumChart", :group => group}.merge(options))
324
+ end
325
+
326
+ # Get a track chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group.
327
+ #
328
+ # +group+:: The last.fm group name to fetch the charts of.
329
+ #
330
+ # <b>Options</b>
331
+ # +from+:: The date at which the chart should start from. See Group.getWeeklyChartList for more.
332
+ # +to+:: The date at which the chart should end on. See Group.getWeeklyChartList for more.
333
+ def weekly_track_chart(group, options={})
334
+ get(:standard, {:method => "group.getWeeklyTrackChart", :group => group}.merge(options))
335
+ end
336
+
337
+ # Get an artist chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group.
338
+ #
339
+ # +group+:: The last.fm group name to fetch the charts of.
340
+ #
341
+ # <b>Options</b>
342
+ # +from+:: The date at which the chart should start from. See Group.getWeeklyChartList for more.
343
+ # +to+:: The date at which the chart should end on. See Group.getWeeklyChartList for more.
344
+ def weekly_artist_chart(group, options={})
345
+ get(:standard, {:method => "group.getWeeklyArtistChart", :group => group}.merge(options))
346
+ end
347
+
348
+ end
349
+
350
+ class Tag < Remote
351
+
352
+ # Search for tags similar to this one. Returns tags ranked by similarity, based on listening data.
353
+ #
354
+ # +tag+:: The tag name in question.
355
+ def similar(tag)
356
+ get(:standard, {:method => "tag.getSimilar", :tag => tag})
357
+ end
358
+
359
+ # Get an artist chart for a tag, for a given date range. If no date range is supplied, it will return the most recent artist chart for this tag.
360
+ #
361
+ # +tag+:: The tag name in question
362
+ #
363
+ # <b>Options</b>
364
+ # +from+:: The date at which the chart should start from. See Tag.getWeeklyChartList for more.
365
+ # +to+:: The date at which the chart should end on. See Tag.getWeeklyChartList for more.
366
+ # +limit+:: The number of chart items to return.
367
+ def weekly_artist_chart(tag, options={})
368
+ get(:standard, {:method => "tag.getWeeklyArtistChart", :tag => tag}.merge(options))
369
+ end
370
+
371
+ # Get the top albums tagged by this tag, ordered by tag count.
372
+ #
373
+ # +tag+:: Last.fm tag
374
+ def top_albums(tag)
375
+ get(:standard, {:method => "tag.getTopAlbums", :tag => tag})
376
+ end
377
+
378
+ # Fetches the top global tags on Last.fm, sorted by popularity (number of times used)
379
+ def top_tags()
380
+ get(:standard, {:method => "tag.getTopTags"})
381
+ end
382
+
383
+ # Search for a tag by name. Returns matches sorted by relevance.
384
+ #
385
+ # +tag+:: The tag name in question.
386
+ #
387
+ # <b>Options</b>
388
+ # +limit+:: Limit the number of tags returned at one time. Default (maximum) is 30.
389
+ # +page+:: Scan into the results by specifying a page number. Defaults to first page.
390
+ def search(tag, options={})
391
+ get(:standard, {:method => "tag.search", :tag => tag}.merge(options))
392
+ end
393
+
394
+ # Get the top artists tagged by this tag, ordered by tag count.
395
+ #
396
+ # +tag+:: Last.fm tag
397
+ def top_artists(tag)
398
+ get(:standard, {:method => "tag.getTopArtists", :tag => tag})
399
+ end
400
+
401
+ # Get the top tracks tagged by this tag, ordered by tag count.
402
+ #
403
+ # +tag+:: Last.fm tag
404
+ def top_tracks(tag)
405
+ get(:standard, {:method => "tag.getTopTracks", :tag => tag})
406
+ end
407
+
408
+ # Get a list of available charts for this tag, expressed as date ranges which can be sent to the chart services.
409
+ #
410
+ # +tag+:: The tag name in question
411
+ def weekly_chart_list(tag)
412
+ get(:standard, {:method => "tag.getWeeklyChartList", :tag => tag})
413
+ end
414
+
415
+ end
416
+
417
+ class Album < Remote
418
+
419
+ # Remove a user's tag from an album.
420
+ #
421
+ # +artist+:: The artist name in question
422
+ # +album+:: The album name in question
423
+ # +tag+:: A single user tag to remove from this album.
424
+ def remove_tag(artist, album, tag)
425
+ post(:session, {:method => "album.removeTag", :artist => artist, :album => album, :tag => tag})
426
+ end
427
+
428
+ # Tag an album using a list of user supplied tags.
429
+ #
430
+ # +artist+:: The artist name in question
431
+ # +album+:: The album name in question
432
+ # +tags+:: A comma delimited list of user supplied tags to apply to this album. Accepts a maximum of 10 tags.
433
+ def add_tags(artist, album, tags)
434
+ post(:session, {:method => "album.addTags", :artist => artist, :album => album, :tags => tags})
435
+ end
436
+
437
+ # Get the metadata for an album on Last.fm using the album name or a musicbrainz id. See playlist.fetch on how to get the album playlist.
438
+ #
439
+ # <b>Options</b>
440
+ # +artist+:: The artist name in question
441
+ # +album+:: The album name in question
442
+ # +mbid+:: The musicbrainz id for the album
443
+ # +lang+:: The language to return the biography in, expressed as an ISO 639 alpha-2 code.
444
+ def info(options={})
445
+ get(:standard, {:method => "album.getInfo"}.merge(options))
446
+ end
447
+
448
+ # Get the tags applied by an individual user to an album on Last.fm.
449
+ #
450
+ # +artist+:: The artist name in question
451
+ # +album+:: The album name in question
452
+ def tags(artist, album)
453
+ get(:session, {:method => "album.getTags", :artist => artist, :album => album})
454
+ end
455
+
456
+ # Search for an album by name. Returns album matches sorted by relevance.
457
+ #
458
+ # +album+:: The album name in question.
459
+ #
460
+ # <b>Options</b>
461
+ # +limit+:: Limit the number of albums returned at one time. Default (maximum) is 30.
462
+ # +page+:: Scan into the results by specifying a page number. Defaults to first page.
463
+ def search(album, options={})
464
+ get(:standard, {:method => "album.search", :album => album}.merge(options))
465
+ end
466
+
467
+ end
468
+
469
+ class Venue < Remote
470
+
471
+ # Get a paginated list of all the events held at this venue in the past.
472
+ #
473
+ # +venue+:: The id for the venue you would like to fetch event listings for.
474
+ #
475
+ # <b>Options</b>
476
+ # +page+:: The page of results to return.
477
+ # +limit+:: The maximum number of results to return.
478
+ def past_events(venue, options={})
479
+ get(:standard, {:method => "venue.getPastEvents", :venue => venue}.merge(options))
480
+ end
481
+
482
+ # Get a list of upcoming events at this venue.
483
+ #
484
+ # +venue+:: The id for the venue you would like to fetch event listings for.
485
+ def events(venue)
486
+ get(:standard, {:method => "venue.getEvents", :venue => venue})
487
+ end
488
+
489
+ # Search for a venue by venue name
490
+ #
491
+ # +venue+:: The venue name you would like to search for.
492
+ #
493
+ # <b>Options</b>
494
+ # +page+:: The results page you would like to fetch
495
+ # +limit+:: The number of results to fetch per page. Defaults to 50.
496
+ # +country+:: Filter your results by country. Expressed as an ISO 3166-2 code.
497
+ def search(venue, options={})
498
+ get(:standard, {:method => "venue.search", :venue => venue}.merge(options))
499
+ end
500
+
501
+ end
502
+
503
+ class Tasteometer < Remote
504
+
505
+ # Get a Tasteometer score from two inputs, along with a list of shared artists. If the input is a User or a Myspace URL, some additional information is returned.
506
+ #
507
+ # +type1+:: 'user' | 'artists' | 'myspace'
508
+ # +type2+:: 'user' | 'artists' | 'myspace'
509
+ # +value1+:: [Last.fm username] | [Comma-separated artist names] | [MySpace profile URL]
510
+ # +value2+:: [Last.fm username] | [Comma-separated artist names] | [MySpace profile URL]
511
+ #
512
+ # <b>Options</b>
513
+ # +limit+:: How many shared artists to display
514
+ def compare(type1, type2, value1, value2, options={})
515
+ get(:standard, {:method => "tasteometer.compare", :type1 => type1, :type2 => type2, :value1 => value1, :value2 => value2}.merge(options))
516
+ end
517
+
518
+ end
519
+
520
+ class Geo < Remote
521
+
522
+ # Get all events in a specific location by country or city name.
523
+ #
524
+ # <b>Options</b>
525
+ # +location+:: Specifies a location to retrieve events for (service returns nearby events by default)
526
+ # +lat+:: Specifies a latitude value to retrieve events for (service returns nearby events by default)
527
+ # +long+:: Specifies a longitude value to retrieve events for (service returns nearby events by default)
528
+ # +page+:: Display more results by pagination
529
+ # +distance+:: Find events within a specified distance
530
+ def events(options={})
531
+ get(:standard, {:method => "geo.getEvents"}.merge(options))
532
+ end
533
+
534
+ # Get the most popular tracks on Last.fm last week by country
535
+ #
536
+ # +country+:: A country name, as defined by the ISO 3166-1 country names standard
537
+ #
538
+ # <b>Options</b>
539
+ # +location+:: A metro name, to fetch the charts for (must be within the country specified)
540
+ def top_tracks(country, options={})
541
+ get(:standard, {:method => "geo.getTopTracks", :country => country}.merge(options))
542
+ end
543
+
544
+ # Get the most popular artists on Last.fm by country
545
+ #
546
+ # +country+:: A country name, as defined by the ISO 3166-1 country names standard
547
+ def top_artists(country)
548
+ get(:standard, {:method => "geo.getTopArtists", :country => country})
549
+ end
550
+
551
+ end
552
+
553
+ class Radio < Remote
554
+
555
+ # Tune in to a Last.fm radio station.
556
+ #
557
+ # +station+:: A lastfm radio URL
558
+ #
559
+ # <b>Options</b>
560
+ # +lang+:: An ISO language code to determine the language to return the station name in, expressed as an ISO 639 alpha-2 code.
561
+ def tune(station, options={})
562
+ post(:session, {:method => "radio.tune", :station => station}.merge(options))
563
+ end
564
+
565
+ # Fetch new radio content periodically in an XSPF format.
566
+ #
567
+ # <b>Options</b>
568
+ # +discovery+:: Whether to request last.fm content with discovery mode switched on.
569
+ # +rtp+:: Whether the user is scrobbling or not during this radio session (helps content generation)
570
+ def playlist(options={})
571
+ get(:session, {:method => "radio.getPlaylist"}.merge(options))
572
+ end
573
+
574
+ end
575
+
576
+ class Library < Remote
577
+
578
+ # A paginated list of all the albums in a user's library, with play counts and tag counts.
579
+ #
580
+ # +user+:: The user whose library you want to fetch.
581
+ #
582
+ # <b>Options</b>
583
+ # +limit+:: Limit the amount of albums returned (maximum/default is 50).
584
+ # +page+:: The page number you wish to scan to.
585
+ def albums(user, options={})
586
+ get(:standard, {:method => "library.getAlbums", :user => user}.merge(options))
587
+ end
588
+
589
+ # A paginated list of all the artists in a user's library, with play counts and tag counts.
590
+ #
591
+ # +user+:: The user whose library you want to fetch.
592
+ #
593
+ # <b>Options</b>
594
+ # +limit+:: Limit the amount of artists returned (maximum/default is 50).
595
+ # +page+:: The page number you wish to scan to.
596
+ def artists(user, options={})
597
+ get(:standard, {:method => "library.getArtists", :user => user}.merge(options))
598
+ end
599
+
600
+ # Add an artist to a user's Last.fm library
601
+ #
602
+ # +artist+:: The artist name you wish to add
603
+ def add_artist(artist)
604
+ post(:session, {:method => "library.addArtist", :artist => artist})
605
+ end
606
+
607
+ # Add a track to a user's Last.fm library
608
+ #
609
+ # +artist+:: The artist that composed the track
610
+ # +track+:: The track name you wish to add
611
+ def add_track(artist, track)
612
+ post(:session, {:method => "library.addTrack", :artist => artist, :track => track})
613
+ end
614
+
615
+ # Add an album to a user's Last.fm library
616
+ #
617
+ # +artist+:: The artist that composed the track
618
+ # +album+:: The album name you wish to add
619
+ def add_album(artist, album)
620
+ post(:session, {:method => "library.addAlbum", :artist => artist, :album => album})
621
+ end
622
+
623
+ # A paginated list of all the tracks in a user's library, with play counts and tag counts.
624
+ #
625
+ # +user+:: The user whose library you want to fetch.
626
+ #
627
+ # <b>Options</b>
628
+ # +limit+:: Limit the amount of tracks returned (maximum/default is 50).
629
+ # +page+:: The page number you wish to scan to.
630
+ def tracks(user, options={})
631
+ get(:standard, {:method => "library.getTracks", :user => user}.merge(options))
632
+ end
633
+
634
+ end
635
+
636
+ class Artist < Remote
637
+
638
+ # Tag an artist with one or more user supplied tags.
639
+ #
640
+ # +artist+:: The artist name in question.
641
+ # +tags+:: A comma delimited list of user supplied tags to apply to this artist. Accepts a maximum of 10 tags.
642
+ def add_tags(artist, tags)
643
+ post(:session, {:method => "artist.addTags", :artist => artist, :tags => tags})
644
+ end
645
+
646
+ # Get a list of upcoming events for this artist. Easily integratable into calendars, using the ical standard (see feeds section below).
647
+ #
648
+ # +artist+:: The artist name in question
649
+ def events(artist)
650
+ get(:standard, {:method => "artist.getEvents", :artist => artist})
651
+ end
652
+
653
+ # Shout in this artist's shoutbox
654
+ #
655
+ # +artist+:: The name of the artist to shout on.
656
+ # +message+:: The message to post to the shoutbox.
657
+ def shout(artist, message)
658
+ post(:session, {:method => "artist.shout", :artist => artist, :message => message})
659
+ end
660
+
661
+ # Share an artist with Last.fm users or other friends.
662
+ #
663
+ # +artist+:: The artist to share.
664
+ # +recipient+:: Email Address | Last.fm Username - A comma delimited list of email addresses or Last.fm usernames. Maximum is 10.
665
+ #
666
+ # <b>Options</b>
667
+ # +message+:: An optional message to send with the recommendation. If not supplied a default message will be used.
668
+ def share(artist, recipient, options={})
669
+ post(:session, {:method => "artist.share", :artist => artist, :recipient => recipient}.merge(options))
670
+ end
671
+
672
+ # Get the top tracks by an artist on Last.fm, ordered by popularity
673
+ #
674
+ # +artist+:: The artist name in question
675
+ def top_tracks(artist)
676
+ get(:standard, {:method => "artist.getTopTracks", :artist => artist})
677
+ end
678
+
679
+ # Get all the artists similar to this artist
680
+ #
681
+ # +artist+:: The artist name in question
682
+ #
683
+ # <b>Options</b>
684
+ # +limit+:: Limit the number of similar artists returned
685
+ def similar(artist, options={})
686
+ get(:standard, {:method => "artist.getSimilar", :artist => artist}.merge(options))
687
+ end
688
+
689
+ # Remove a user's tag from an artist.
690
+ #
691
+ # +artist+:: The artist name in question.
692
+ # +tag+:: A single user tag to remove from this artist.
693
+ def remove_tag(artist, tag)
694
+ post(:session, {:method => "artist.removeTag", :artist => artist, :tag => tag})
695
+ end
696
+
697
+ # Search for an artist by name. Returns artist matches sorted by relevance.
698
+ #
699
+ # +artist+:: The artist name in question.
700
+ #
701
+ # <b>Options</b>
702
+ # +limit+:: Limit the number of artists returned at one time. Default (maximum) is 30.
703
+ # +page+:: Scan into the results by specifying a page number. Defaults to first page.
704
+ def search(artist, options={})
705
+ get(:standard, {:method => "artist.search", :artist => artist}.merge(options))
706
+ end
707
+
708
+ # Get Images for this artist in a variety of sizes.
709
+ #
710
+ # +artist+:: The artist name in question.
711
+ #
712
+ # <b>Options</b>
713
+ # +page+:: Which page of limit amount to display.
714
+ # +limit+:: How many to return. Defaults and maxes out at 50.
715
+ # +order+:: Sort ordering can be either 'popularity' (default) or 'dateadded'. While ordering by popularity officially selected images by labels and artists will be ordered first. This is ignored and set to 'dateadded' when requested as rss.
716
+ def images(artist, options={})
717
+ get(:standard, {:method => "artist.getImages", :artist => artist}.merge(options))
718
+ end
719
+
720
+ # Get the top tags for an artist on Last.fm, ordered by popularity.
721
+ #
722
+ # +artist+:: The artist name in question
723
+ def top_tags(artist)
724
+ get(:standard, {:method => "artist.getTopTags", :artist => artist})
725
+ end
726
+
727
+ # Get the metadata for an artist on Last.fm. Includes biography.
728
+ #
729
+ # <b>Options</b>
730
+ # +artist+:: The artist name in question
731
+ # +mbid+:: The musicbrainz id for the artist
732
+ # +lang+:: The language to return the biography in, expressed as an ISO 639 alpha-2 code.
733
+ def info(options={})
734
+ get(:standard, {:method => "artist.getInfo"}.merge(options))
735
+ end
736
+
737
+ # Get shouts for this artist. Also available as an rss feed.
738
+ #
739
+ # +artist+:: The artist name in question.
740
+ def shouts(artist)
741
+ get(:standard, {:method => "artist.getShouts", :artist => artist})
742
+ end
743
+
744
+ # Get the tags applied by an individual user to an artist on Last.fm.
745
+ #
746
+ # +artist+:: The artist name in question
747
+ def tags(artist)
748
+ get(:session, {:method => "artist.getTags", :artist => artist})
749
+ end
750
+
751
+ # Get the top albums for an artist on Last.fm, ordered by popularity.
752
+ #
753
+ # +artist+:: The artist name in question
754
+ def top_albums(artist)
755
+ get(:standard, {:method => "artist.getTopAlbums", :artist => artist})
756
+ end
757
+
758
+ # Get the top fans for an artist on Last.fm, based on listening data.
759
+ #
760
+ # +artist+:: The artist name in question
761
+ def top_fans(artist)
762
+ get(:standard, {:method => "artist.getTopFans", :artist => artist})
763
+ end
764
+
765
+ end
766
+
767
+ class Event < Remote
768
+
769
+ # Share an event with one or more Last.fm users or other friends.
770
+ #
771
+ # +event+:: An event ID
772
+ # +recipient+:: Email Address | Last.fm Username - A comma delimited list of email addresses or Last.fm usernames. Maximum is 10.
773
+ #
774
+ # <b>Options</b>
775
+ # +message+:: An optional message to send with the recommendation. If not supplied a default message will be used.
776
+ def share(event, recipient, options={})
777
+ post(:session, {:method => "event.share", :event => event, :recipient => recipient}.merge(options))
778
+ end
779
+
780
+ # Get a list of attendees for an event.
781
+ #
782
+ # +event+:: The numeric last.fm event id
783
+ def attendees(event)
784
+ get(:standard, {:method => "event.getAttendees", :event => event})
785
+ end
786
+
787
+ # Shout in this event's shoutbox
788
+ #
789
+ # +event+:: The id of the event to shout on
790
+ # +message+:: The message to post to the shoutbox
791
+ def shout(event, message)
792
+ post(:session, {:method => "event.shout", :event => event, :message => message})
793
+ end
794
+
795
+ # Set a user's attendance status for an event.
796
+ #
797
+ # +event+:: The numeric last.fm event id
798
+ # +status+:: The attendance status (0=Attending, 1=Maybe attending, 2=Not attending)
799
+ def attend(event, status)
800
+ post(:session, {:method => "event.attend", :event => event, :status => status})
801
+ end
802
+
803
+ # Get the metadata for an event on Last.fm. Includes attendance and lineup information.
804
+ #
805
+ # +event+:: The numeric last.fm event id
806
+ def info(event)
807
+ get(:standard, {:method => "event.getInfo", :event => event})
808
+ end
809
+
810
+ # Get shouts for this event. Also available as an rss feed.
811
+ #
812
+ # +event+:: The numeric last.fm event id
813
+ def shouts(event)
814
+ get(:standard, {:method => "event.getShouts", :event => event})
815
+ end
816
+
817
+ end
818
+
819
+ class Auth < Remote
820
+
821
+ # Fetch an unathorized request token for an API account. This is step 2 of the authentication process for desktop applications. Web applications do not need to use this service.
822
+ def token()
823
+ get(:signed, {:method => "auth.getToken"})
824
+ end
825
+
826
+ # Used by our flash embeds (on trusted domains) to use a site session cookie to seed a ws session without requiring a password. Uses the site cookie so must be accessed over a .last.fm domain.
827
+ def web_session()
828
+ get(:signed, {:method => "auth.getWebSession"})
829
+ end
830
+
831
+ # Create a web service session for a user. Used for authenticating a user when the password can be inputted by the user. Only suitable for standalone mobile devices. See the authentication how-to for more.
832
+ #
833
+ # +username+:: The last.fm username.
834
+ # +authToken+:: A 32-byte ASCII hexadecimal MD5 hash of the last.fm username and the user's password hash. i.e. md5(username + md5(password)), where '+' represents a concatenation.
835
+ def mobile_session(username, authToken)
836
+ get(:signed, {:method => "auth.getMobileSession", :username => username, :authToken => authToken})
837
+ end
838
+
839
+ # Fetch a session key for a user. The third step in the authentication process. See the authentication how-to for more information.
840
+ #
841
+ # +token+:: A 32-character ASCII hexadecimal MD5 hash returned by step 1 of the authentication process (following the granting of permissions to the application by the user)
842
+ def session(token)
843
+ get(:signed, {:method => "auth.getSession", :token => token})
844
+ end
845
+
846
+ end
847
+
848
+ class Playlist < Remote
849
+
850
+ # Create a Last.fm playlist on behalf of a user
851
+ #
852
+ # <b>Options</b>
853
+ # +title+:: Title for the playlist
854
+ # +description+:: Description for the playlist
855
+ def create(options={})
856
+ post(:session, {:method => "playlist.create"}.merge(options))
857
+ end
858
+
859
+ # Add a track to a Last.fm user's playlist
860
+ #
861
+ # +playlistID+:: The ID of the playlist - this is available in user.getPlaylists.
862
+ # +track+:: The track name to add to the playlist.
863
+ # +artist+:: The artist name that corresponds to the track to be added.
864
+ def add_track(playlistID, track, artist)
865
+ post(:session, {:method => "playlist.addTrack", :playlistID => playlistID, :track => track, :artist => artist})
866
+ end
867
+
868
+ # Fetch XSPF playlists using a lastfm playlist url.
869
+ #
870
+ # +playlistURL+:: A lastfm protocol playlist url ('lastfm://playlist/...') . See 'playlists' section for more information.
871
+ def fetch(playlistURL)
872
+ get(:standard, {:method => "playlist.fetch", :playlistURL => playlistURL})
873
+ end
874
+
875
+ end
876
+
877
+ end
878
+ end