rscrobbler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ module LastFM
2
+ class Album
3
+ class << self
4
+
5
+ TYPE = 'album'
6
+
7
+ # @see http://www.last.fm/api/show?service=302
8
+ def add_tags( artist, album, tags )
9
+ LastFM.requires_authentication
10
+ LastFM.post( "#{TYPE}.addTags", 'artist'=>artist, 'album'=>album, 'tags'=>tags )
11
+ end
12
+
13
+ # @see http://www.last.fm/api/show?service=429
14
+ def get_buylinks( country, artist = nil, album = nil, mbid = nil, autocorrect = nil )
15
+ raise ArgumentError unless artist && album || mbid
16
+ LastFM.get( "#{TYPE}.getBuylinks", !:secure, 'country'=>country, 'artist'=>artist, 'album'=>album, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
17
+ end
18
+
19
+ # @see http://www.last.fm/api/show?service=290
20
+ def get_info( artist = nil, album = nil, mbid = nil, lang = nil, autocorrect = nil, username = nil )
21
+ raise ArgumentError unless artist && album || mbid
22
+ LastFM.get( "#{TYPE}.getInfo", !:secure, 'artist'=>artist, 'album'=>album, 'mbid'=>mbid, 'lang'=>lang, 'autocorrect'=>autocorrect, 'username'=>username )
23
+ end
24
+
25
+ # @see http://www.last.fm/api/show?service=450
26
+ def get_shouts( artist = nil, album = nil, mbid = nil, autocorrect = nil, limit = nil, page = nil )
27
+ raise ArgumentError unless artist && album || mbid
28
+ LastFM.get( "#{TYPE}.getShouts", !:secure, 'artist'=>artist, 'album'=>album, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit, 'page'=>page )
29
+ end
30
+
31
+ # @see http://www.last.fm/api/show?service=317
32
+ def get_tags( artist = nil, album = nil, mbid = nil, autocorrect = nil )
33
+ raise ArgumentError unless artist && album || mbid
34
+ LastFM.requires_authentication
35
+ LastFM.get( "#{TYPE}.getTags", :secure, 'artist'=>artist, 'album'=>album, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
36
+ end
37
+
38
+ # @see http://www.last.fm/api/show?service=438
39
+ def get_top_tags( artist = nil, album = nil, mbid = nil, autocorrect = nil )
40
+ raise ArgumentError unless artist && album || mbid
41
+ LastFM.get( "#{TYPE}.getTopTags", !:secure, 'artist'=>artist, 'album'=>album, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
42
+ end
43
+
44
+ # @see http://www.last.fm/api/show?service=314
45
+ def remove_tag( artist, album, tag )
46
+ LastFM.requires_authentication
47
+ LastFM.post( "#{TYPE}.removeTag", 'artist'=>artist, 'album'=>album, 'tag'=>tag )
48
+ end
49
+
50
+ # @see http://www.last.fm/api/show?service=357
51
+ def search( album, limit = nil, page = nil )
52
+ LastFM.get( "#{TYPE}.search", !:secure, 'album'=>album, 'limit'=>limit, 'page'=>page )
53
+ end
54
+
55
+ # @see http://www.last.fm/api/show?service=436
56
+ def share( artist, album, recipient, message = nil, public = nil )
57
+ LastFM.requires_authentication
58
+ LastFM.post( "#{TYPE}.share", 'artist'=>artist, 'album'=>album, 'recipient'=>recipient, 'message'=>message, 'public'=>public )
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,116 @@
1
+ module LastFM
2
+ class Artist
3
+ class << self
4
+
5
+ TYPE = 'artist'
6
+
7
+ # @see http://www.last.fm/api/show/?service=303
8
+ def add_tags( artist, tags )
9
+ LastFM.requires_authentication
10
+ LastFM.post( "#{TYPE}.addTags", 'artist'=>artist, 'tags'=>tags )
11
+ end
12
+
13
+ # @see http://www.last.fm/api/show/?service=446
14
+ def get_correction( artist )
15
+ LastFM.get( "#{TYPE}.getCorrection", !:secure, 'artist'=>artist )
16
+ end
17
+
18
+ # @see http://www.last.fm/api/show/?service=117
19
+ def get_events( artist = nil, mbid = nil, autocorrect = nil, festivals_only = nil, limit = nil, page = nil)
20
+ raise ArgumentError unless artist || mbid
21
+ LastFM.get( "#{TYPE}.getEvents", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'festivalsonly'=>festivals_only, 'limit'=>limit, 'page'=>page )
22
+ end
23
+
24
+ # @see http://www.last.fm/api/show/?service=407
25
+ def get_images( artist = nil, mbid = nil, autocorrect = nil, order = nil, limit = nil, page = nil )
26
+ raise ArgumentError unless artist || mbid
27
+ LastFM.get( "#{TYPE}.getImages", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'order'=>order, 'limit'=>limit, 'page'=>page )
28
+ end
29
+
30
+ # @see http://www.last.fm/api/show/?service=267
31
+ def get_info( artist = nil, mbid = nil, lang = nil, autocorrect = nil, username = nil )
32
+ raise ArgumentError unless artist || mbid
33
+ LastFM.get( "#{TYPE}.getInfo", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'lang'=>lang, 'username'=>username )
34
+ end
35
+
36
+ # @see http://www.last.fm/api/show/?service=428
37
+ def get_past_events( artist = nil, mbid = nil, autocorrect = nil, limit = nil, page = nil )
38
+ raise ArgumentError unless artist || mbid
39
+ LastFM.get( "#{TYPE}.getPastEvents", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit, 'page'=>page )
40
+ end
41
+
42
+ # @see http://www.last.fm/api/show/?service=118
43
+ def get_podcast( artist = nil, mbid = nil, autocorrect = nil )
44
+ raise ArgumentError unless artist || mbid
45
+ LastFM.get( "#{TYPE}.getPodcast", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
46
+ end
47
+
48
+ # @see http://www.last.fm/api/show/?service=397
49
+ def get_shouts( artist = nil, mbid = nil, autocorrect = nil, limit = nil, page = nil )
50
+ raise ArgumentError unless artist || mbid
51
+ LastFM.get( "#{TYPE}.getShouts", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit, 'page'=>page )
52
+ end
53
+
54
+ # @see http://www.last.fm/api/show/?service=119
55
+ def get_similar( artist = nil, mbid = nil, autocorrect = nil, limit = nil )
56
+ raise ArgumentError unless artist || mbid
57
+ LastFM.get( "#{TYPE}.getSimilar", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit )
58
+ end
59
+
60
+ # @see http://www.last.fm/api/show/?service=318
61
+ def get_tags( artist = nil, mbid = nil, autocorrect = nil )
62
+ raise ArgumentError unless artist || mbid
63
+ LastFM.requires_authentication
64
+ LastFM.get( "#{TYPE}.getTags", :secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
65
+ end
66
+
67
+ # @see http://www.last.fm/api/show/?service=287
68
+ def get_top_albums( artist = nil, mbid = nil, autocorrect = nil, limit = nil, page = nil )
69
+ raise ArgumentError unless artist || mbid
70
+ LastFM.get( "#{TYPE}.getTopAlbums", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit, 'page'=>page )
71
+ end
72
+
73
+ # @see http://www.last.fm/api/show/?service=310
74
+ def get_top_fans( artist = nil, mbid = nil, autocorrect = nil )
75
+ raise ArgumentError unless artist || mbid
76
+ LastFM.get( "#{TYPE}.getTopFans", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
77
+ end
78
+
79
+ # @see http://www.last.fm/api/show/?service=288
80
+ def get_top_tags( artist = nil, mbid = nil, autocorrect = nil )
81
+ raise ArgumentError unless artist || mbid
82
+ LastFM.get( "#{TYPE}.getTopTags", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
83
+ end
84
+
85
+ # @see http://www.last.fm/api/show/?service=277
86
+ def get_top_tracks( artist = nil, mbid = nil, autocorrect = nil, limit = nil, page = nil )
87
+ raise ArgumentError unless artist || mbid
88
+ LastFM.get( "#{TYPE}.getTopTracks", !:secure, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit, 'page'=>page )
89
+ end
90
+
91
+ # @see http://www.last.fm/api/show/?service=315
92
+ def remove_tag( artist, tag )
93
+ LastFM.requires_authentication
94
+ LastFM.post( "#{TYPE}.removeTag", 'artist'=>artist, 'tag'=>tag )
95
+ end
96
+
97
+ # @see http://www.last.fm/api/show/?service=272
98
+ def search( artist, limit = nil, page = nil )
99
+ LastFM.get( "#{TYPE}.search", !:secure, 'artist'=>artist, 'limit'=>limit, 'page'=>page )
100
+ end
101
+
102
+ # @see http://www.last.fm/api/show/?service=306
103
+ def share( artist, recipient, message = nil, public = nil )
104
+ LastFM.requires_authentication
105
+ LastFM.post( "#{TYPE}.share", 'artist'=>artist, 'recipient'=>recipient, 'message'=>message, 'public'=>public )
106
+ end
107
+
108
+ # @see http://www.last.fm/api/show/?service=408
109
+ def shout( artist, message )
110
+ LastFM.requires_authentication
111
+ LastFM.post( "#{TYPE}.shout", 'artist'=>artist, 'message'=>message )
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,24 @@
1
+ module LastFM
2
+ class Auth
3
+ class << self
4
+
5
+ TYPE = 'auth'
6
+
7
+ # @see http://www.last.fm/api/show?service=266
8
+ def get_mobile_session( username, auth_token )
9
+ LastFM.get( "#{TYPE}.getMobileSession", :secure, 'username' => username, 'authToken' => auth_token )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show?service=125
13
+ def get_session( token )
14
+ LastFM.get( "#{TYPE}.getSession", :secure )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show?service=265
18
+ def get_token()
19
+ LastFM.get( "#{TYPE}.getToken", :secure )
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ module LastFM
2
+ class Chart
3
+ class << self
4
+
5
+ TYPE = 'chart'
6
+
7
+ # @see http://www.last.fm/api/show?service=493
8
+ def get_hyped_artists( limit = nil, page = nil )
9
+ LastFM.get( "#{TYPE}.getHypedArtists", !:secure, 'limit'=>limit, 'page'=>page )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show?service=494
13
+ def get_hyped_tracks( limit = nil, page = nil )
14
+ LastFM.get( "#{TYPE}.getHypedTracks", !:secure, 'limit'=>limit, 'page'=>page )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show?service=495
18
+ def get_loved_tracks( limit = nil, page = nil )
19
+ LastFM.get( "#{TYPE}.getLovedTracks", !:secure, 'limit'=>limit, 'page'=>page )
20
+ end
21
+
22
+ # @see http://www.last.fm/api/show?service=496
23
+ def get_top_artists( limit = nil, page = nil )
24
+ LastFM.get( "#{TYPE}.getTopArtists", !:secure, 'limit'=>limit, 'page'=>page )
25
+ end
26
+
27
+ # @see http://www.last.fm/api/show?service=497
28
+ def get_top_tags( limit = nil, page = nil )
29
+ LastFM.get( "#{TYPE}.getTopTags", !:secure, 'limit'=>limit, 'page'=>page )
30
+ end
31
+
32
+ # @see http://www.last.fm/api/show?service=498
33
+ def get_top_tracks( limit = nil, page = nil )
34
+ LastFM.get( "#{TYPE}.getTopTracks", !:secure, 'limit'=>limit, 'page'=>page )
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ module LastFM
2
+ class Event
3
+ class << self
4
+
5
+ TYPE = 'event'
6
+
7
+ # @see http://www.last.fm/api/show?service=307
8
+ def attend( event, status )
9
+ LastFM.requires_authentication
10
+ LastFM.post( "#{TYPE}.attend", 'event'=>event, 'status'=>status )
11
+ end
12
+
13
+ # @see http://www.last.fm/api/show?service=391
14
+ def get_attendees( event, limit = nil, page = nil )
15
+ LastFM.get( "#{TYPE}.getAttendees", !:secure, 'event'=>event, 'limit'=>limit, 'page'=>page )
16
+ end
17
+
18
+ # @see http://www.last.fm/api/show?service=292
19
+ def get_info( event )
20
+ LastFM.get( "#{TYPE}.getInfo", !:secure, 'event'=>event )
21
+ end
22
+
23
+ # @see http://www.last.fm/api/show?service=399
24
+ def get_shouts( event, limit = nil, page = nil )
25
+ LastFM.get( "#{TYPE}.getShouts", !:secure, 'event'=>event, 'limit'=>limit, 'page'=>page )
26
+ end
27
+
28
+ # @see http://www.last.fm/api/show?service=350
29
+ def share( event, recipient, message = nil, public = nil )
30
+ LastFM.requires_authentication
31
+ LastFM.post( "#{TYPE}.share", 'event'=>event, 'recipient'=>recipient, 'public'=>public, 'message'=>message )
32
+ end
33
+
34
+ # @see http://www.last.fm/api/show?service=409
35
+ def shout( event, message )
36
+ LastFM.requires_authentication
37
+ LastFM.post( "#{TYPE}.shout", 'event'=>event, 'message'=>message )
38
+ end
39
+
40
+ end
41
+ end
42
+ end
data/lib/lastfm/geo.rb ADDED
@@ -0,0 +1,64 @@
1
+ module LastFM
2
+ class Geo
3
+ class << self
4
+
5
+ TYPE = 'geo'
6
+
7
+ # @see http://www.last.fm/api/show?service=270
8
+ def get_events( location = nil, lat = nil, long = nil, distance = nil, limit = nil, page = nil )
9
+ LastFM.get( "#{TYPE}.getEvents", !:secure, 'location'=>location, 'lat'=>lat, 'long'=>long, 'distance'=>distance, 'limit'=>limit, 'page'=>page )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show?service=421
13
+ def get_metro_artist_chart( country, metro, time_start = nil, time_end = nil )
14
+ LastFM.get( "#{TYPE}.getMetroArtistChart", !:secure, 'country'=>country, 'metro'=>metro, 'start'=>time_start, 'end'=>time_end )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show?service=420
18
+ def get_metro_hype_artist_chart( country, metro, time_start = nil, time_end = nil )
19
+ LastFM.get( "#{TYPE}.getMetroHypeArtistChart", !:secure, 'country'=>country, 'metro'=>metro, 'start'=>time_start, 'end'=>time_end )
20
+ end
21
+
22
+ # @see http://www.last.fm/api/show?service=422
23
+ def get_metro_hype_track_chart( country, metro, time_start = nil, time_end = nil )
24
+ LastFM.get( "#{TYPE}.getMetroHypeTrackChart", !:secure, 'country'=>country, 'metro'=>metro, 'start'=>time_start, 'end'=>time_end )
25
+ end
26
+
27
+ # @see http://www.last.fm/api/show?service=423
28
+ def get_metro_track_chart( country, metro, time_start = nil, time_end = nil )
29
+ LastFM.get( "#{TYPE}.getMetroTrackChart", !:secure, 'country'=>country, 'metro'=>metro, 'start'=>time_start, 'end'=>time_end )
30
+ end
31
+
32
+ # @see http://www.last.fm/api/show?service=424
33
+ def get_metro_unique_artist_chart( country, metro, time_start = nil, time_end = nil )
34
+ LastFM.get( "#{TYPE}.getMetroUniqueArtistChart", !:secure, 'country'=>country, 'metro'=>metro, 'start'=>time_start, 'end'=>time_end )
35
+ end
36
+
37
+ # @see http://www.last.fm/api/show?service=425
38
+ def get_metro_unique_track_chart( country, metro, time_start = nil, time_end = nil )
39
+ LastFM.get( "#{TYPE}.getMetroUniqueTrackChart", !:secure, 'country'=>country, 'metro'=>metro, 'start'=>time_start, 'end'=>time_end )
40
+ end
41
+
42
+ # @see http://www.last.fm/api/show?service=426
43
+ def get_metro_weekly_chartlist( metro )
44
+ LastFM.get( "#{TYPE}.getMetroWeeklyChartlist", !:secure, 'metro'=>metro )
45
+ end
46
+
47
+ # @see http://www.last.fm/api/show?service=435
48
+ def get_metros( country = nil )
49
+ LastFM.get( "#{TYPE}.getMetros", !:secure, 'country'=>country )
50
+ end
51
+
52
+ # @see http://www.last.fm/api/show?service=297
53
+ def get_top_artists( country, limit = nil, page = nil )
54
+ LastFM.get( "#{TYPE}.getTopArtists", !:secure, 'country'=>country, 'limit'=>limit, 'page'=>page )
55
+ end
56
+
57
+ # @see http://www.last.fm/api/show?service=298
58
+ def get_top_tracks( country, location = nil, limit = nil, page = nil )
59
+ LastFM.get( "#{TYPE}.getTopTracks", !:secure, 'country'=>country, 'location'=>location, 'limit'=>limit, 'page'=>page )
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,39 @@
1
+ module LastFM
2
+ class Group
3
+ class << self
4
+
5
+ TYPE = 'group'
6
+
7
+ # @see http://www.last.fm/api/show?service=259
8
+ def get_hype( group )
9
+ LastFM.get( "#{TYPE}.getHype", !:secure, 'group'=>group )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show/?service=379
13
+ def get_members( group, limit = nil, page = nil )
14
+ LastFM.get( "#{TYPE}.getMembers", !:secure, 'group'=>group, 'limit'=>limit, 'page'=>page )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show/?service=293
18
+ def get_weekly_album_chart( group, date_from = nil, date_to = nil )
19
+ LastFM.get( "#{TYPE}.getWeeklyAlbumChart", !:secure, 'group'=>group, 'from'=>date_from, 'to'=>date_to )
20
+ end
21
+
22
+ # @see http://www.last.fm/api/show/?service=294
23
+ def get_weekly_artist_chart( group, date_from = nil, date_to = nil )
24
+ LastFM.get( "#{TYPE}.getWeeklyArtistChart", !:secure, 'group'=>group, 'from'=>date_from, 'to'=>date_to )
25
+ end
26
+
27
+ # @see http://www.last.fm/api/show/?service=295
28
+ def get_weekly_chart_list( group )
29
+ LastFM.get( "#{TYPE}.getWeeklyChartList", !:secure, 'group'=>group )
30
+ end
31
+
32
+ # @see http://www.last.fm/api/show/?service=296
33
+ def get_weekly_track_chart( group, date_from = nil, date_to = nil )
34
+ LastFM.get( "#{TYPE}.getWeeklyTrackChart", !:secure, 'group'=>group, 'from'=>date_from, 'to'=>date_to )
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,66 @@
1
+ module LastFM
2
+ class Library
3
+ class << self
4
+
5
+ TYPE = 'library'
6
+
7
+ # see: http://www.last.fm/api/show?service=370
8
+ def add_album( artist, album )
9
+ LastFM.requires_authentication
10
+ LastFM.post( "#{TYPE}.addAlbum", 'artist'=>artist, 'album'=>album )
11
+ end
12
+
13
+ # see: http://www.last.fm/api/show?service=371
14
+ def add_artist( artist )
15
+ LastFM.requires_authentication
16
+ LastFM.post( "#{TYPE}.addArtist", 'artist'=>artist )
17
+ end
18
+
19
+ # see: http://www.last.fm/api/show?service=372
20
+ def add_track( track, artist )
21
+ LastFM.requires_authentication
22
+ LastFM.post( "#{TYPE}.addTrack", 'track'=>track, 'artist'=>artist )
23
+ end
24
+
25
+ # see: http://www.last.fm/api/show?service=321
26
+ def get_albums( user, artist = nil, limit = nil, page = nil )
27
+ LastFM.get( "#{TYPE}.getAlbums", !:secure, 'user'=>user, 'artist'=>artist, 'limit'=>limit, 'page'=>page )
28
+ end
29
+
30
+ # see: http://www.last.fm/api/show?service=322
31
+ def get_artists( user, limit = nil, page = nil )
32
+ LastFM.get( "#{TYPE}.getArtists", !:secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
33
+ end
34
+
35
+ # see: http://www.last.fm/api/show?service=323
36
+ def get_tracks( user, artist = nil, album = nil, limit = nil, page = nil )
37
+ LastFM.get( "#{TYPE}.getTracks", !:secure, 'user'=>user, 'artist'=>artist, 'album'=>album, 'limit'=>limit, 'page'=>page )
38
+ end
39
+
40
+ # see: http://www.last.fm/api/show?service=523
41
+ def remove_album( artist, album )
42
+ LastFM.requires_authentication
43
+ LastFM.post( "#{TYPE}.removeAlbum", 'artist'=>artist, 'album'=>album )
44
+ end
45
+
46
+ # see: http://www.last.fm/api/show?service=524
47
+ def remove_artist( artist )
48
+ LastFM.requires_authentication
49
+ LastFM.post( "#{TYPE}.removeArtist", 'artist'=>artist )
50
+ end
51
+
52
+ # see: http://www.last.fm/api/show?service=525
53
+ def remove_scrobble( track, artist, timestamp )
54
+ LastFM.requires_authentication
55
+ LastFM.post( "#{TYPE}.removeScrobble", 'track'=>track, 'artist'=>artist, 'timestamp'=>timestamp )
56
+ end
57
+
58
+ # see: http://www.last.fm/api/show?service=526
59
+ def remove_track( track, artist )
60
+ LastFM.requires_authentication
61
+ LastFM.post( "#{TYPE}.removeTrack", 'track'=>track, 'artist'=>artist )
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ module LastFM
2
+ class Playlist
3
+ class << self
4
+
5
+ TYPE = 'playlist'
6
+
7
+ # see: http://www.last.fm/api/show?service=337
8
+ def add_track( playlist_id, artist, track )
9
+ LastFM.requires_authentication
10
+ LastFM.post( "#{TYPE}.addTrack", 'playlistID'=>playlist_id, 'artist'=>artist, 'track'=>track )
11
+ end
12
+
13
+ # see: http://www.last.fm/api/show?service=365
14
+ def create( title = nil, description = nil )
15
+ LastFM.requires_authentication
16
+ LastFM.post( "#{TYPE}.create", 'title'=>title, 'description'=>description )
17
+ end
18
+
19
+ # see: http://www.last.fm/api/show?service=271
20
+ def fetch( playlist_url )
21
+ LastFM.get( "#{TYPE}.fetch", !:secure, 'playlistURL'=>playlist_url )
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module LastFM
2
+ class Radio
3
+ class << self
4
+
5
+ TYPE = 'radio'
6
+
7
+ # see: http://www.last.fm/api/show?service=256
8
+ def get_playlist( discovery = nil, rtp = nil, buylinks = nil, speed_multiplier = nil, bitrate = nil )
9
+ raise ArgumentError unless [1.0, 2.0].include?(speed_multiplier) && [64, 128].include?(bitrate)
10
+ LastFM.requires_authentication
11
+ LastFM.get( "#{TYPE}.getPlaylist", :secure, 'discovery'=>discovery, 'rtp'=>rtp, 'buylinks'=>buylinks, 'speed_multiplier'=>speed_multiplier, 'bitrate'=>bitrate )
12
+ end
13
+
14
+ # see: http://www.last.fm/api/show?service=418
15
+ def search( name )
16
+ LastFM.get( "#{TYPE}.search", !:secure, 'name'=>name )
17
+ end
18
+
19
+ # see: http://www.last.fm/api/show?service=160
20
+ def tune( station, lang = nil )
21
+ LastFM.requires_authentication
22
+ LastFM.post( "#{TYPE}.tune", 'station'=>station, 'lang'=>lang )
23
+ end
24
+
25
+ end
26
+ end
27
+ end
data/lib/lastfm/tag.rb ADDED
@@ -0,0 +1,54 @@
1
+ module LastFM
2
+ class Tag
3
+ class << self
4
+
5
+ TYPE = 'tag'
6
+
7
+ # @see http://www.last.fm/api/show?service=452
8
+ def get_info( tag, lang = nil )
9
+ LastFM.get( "#{TYPE}.getInfo", !:secure, 'tag'=>tag, 'lang'=>lang )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show?service=311
13
+ def get_similar( tag )
14
+ LastFM.get( "#{TYPE}.getSimilar", !:secure, 'tag'=>tag )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show?service=283
18
+ def get_top_albums( tag, limit = nil, page = nil )
19
+ LastFM.get( "#{TYPE}.getTopAlbums", !:secure, 'tag'=>tag, 'limit'=>limit, 'page'=>page )
20
+ end
21
+
22
+ # @see http://www.last.fm/api/show?service=284
23
+ def get_top_artists( tag, limit = nil, page = nil )
24
+ LastFM.get( "#{TYPE}.getTopArtists", !:secure, 'tag'=>tag, 'limit'=>limit, 'page'=>page )
25
+ end
26
+
27
+ # @see http://www.last.fm/api/show?service=276
28
+ def get_top_tags
29
+ LastFM.get( "#{TYPE}.getTopTags", !:secure )
30
+ end
31
+
32
+ # @see http://www.last.fm/api/show?service=285
33
+ def get_top_tracks( tag, limit = nil, page = nil )
34
+ LastFM.get( "#{TYPE}.getTopTracks", !:secure, 'tag'=>tag, 'limit'=>limit, 'page'=>page )
35
+ end
36
+
37
+ # @see http://www.last.fm/api/show?service=358
38
+ def get_weekly_artist_chart( tag, time_from = nil, time_to = nil, limit = nil )
39
+ LastFM.get( "#{TYPE}.getWeeklyArtistChart", !:secure, 'tag'=>tag, 'from'=>time_from, 'to'=>time_to, 'limit'=>limit )
40
+ end
41
+
42
+ # @see http://www.last.fm/api/show?service=359
43
+ def get_weekly_chart_list( tag )
44
+ LastFM.get( "#{TYPE}.getWeeklyChartList", !:secure, 'tag'=>tag )
45
+ end
46
+
47
+ # @see http://www.last.fm/api/show?service=273
48
+ def search( tag, limit = nil, page = nil )
49
+ LastFM.get( "#{TYPE}.search", !:secure, 'tag'=>tag, 'limit'=>limit, 'page'=>page )
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ module LastFM
2
+ class Tasteometer
3
+ class << self
4
+
5
+ TYPE = 'tasteometer'
6
+
7
+ # @see http://www.last.fm/api/show?service=258
8
+ def compare( type_1, type_2, value_1, value_2, limit = nil )
9
+ raise ArgumentError unless [ 'user', 'artists', 'myspace' ].include?(type_1) && [ 'user', 'artists', 'myspace' ].include?(type_2)
10
+ LastFM.get( "#{TYPE}.compare", !:secure, 'type1'=>type_1, 'type2'=>type_2, 'value1'=>value_1, 'value2'=>value_2 )
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,121 @@
1
+ module LastFM
2
+ class Track
3
+ class << self
4
+
5
+ TYPE = 'track'
6
+
7
+ # @see http://www.last.fm/api/show?service=304
8
+ def add_tags( track, artist, tags )
9
+ LastFM.requires_authentication
10
+ LastFM.post( "#{TYPE}.addTags", 'track'=>track, 'artist'=>artist, 'tags'=>tags )
11
+ end
12
+
13
+ # @see http://www.last.fm/api/show?service=261
14
+ def ban( track, artist )
15
+ LastFM.requires_authentication
16
+ LastFM.post( "#{TYPE}.ban", 'track'=>track, 'artist'=>artist )
17
+ end
18
+
19
+ # @see http://www.last.fm/api/show?service=431
20
+ def get_buylinks( track = nil, artist = nil, mbid = nil, autocorrect = nil, country = nil )
21
+ raise ArgumentError unless artist && track || mbid
22
+ LastFM.get( "#{TYPE}.getBuylinks", !:secure, 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'country'=>country )
23
+ end
24
+
25
+ # @see http://www.last.fm/api/show?service=447
26
+ def get_correction( track, artist )
27
+ LastFM.get( "#{TYPE}.getCorrection", !:secure, 'track'=>track, 'artist'=>artist )
28
+ end
29
+
30
+ # @see http://www.last.fm/api/show?service=441
31
+ def get_fingerprint_metadata( fingerprint_id )
32
+ LastFM.get( "#{TYPE}.getFingerPrintMetadata", !:secure, 'fingerprintid'=>fingerprint_id )
33
+ end
34
+
35
+ # @see http://www.last.fm/api/show?service=356
36
+ def get_info( track = nil, artist = nil, mbid = nil, autocorrect = nil, username = nil )
37
+ raise ArgumentError unless artist && track || mbid
38
+ LastFM.get( "#{TYPE}.getInfo", !:secure, 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'username'=>username )
39
+ end
40
+
41
+ # @see http://www.last.fm/api/show?service=453
42
+ def get_shouts( track = nil, artist = nil, mbid = nil, autocorrect = nil, limit = nil, page = nil )
43
+ raise ArgumentError unless artist && track || mbid
44
+ LastFM.get( "#{TYPE}.getShouts", !:secure, 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit, 'page'=>page )
45
+ end
46
+
47
+ # @see http://www.last.fm/api/show?service=319
48
+ def get_similar( track = nil, artist = nil, mbid = nil, autocorrect = nil, limit = nil )
49
+ raise ArgumentError unless artist && track || mbid
50
+ LastFM.get( "#{TYPE}.getSimilar", !:secure, 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect, 'limit'=>limit )
51
+ end
52
+
53
+ # @see http://www.last.fm/api/show?service=320
54
+ def get_tags( track = nil, artist = nil, mbid = nil, autocorrect = nil )
55
+ raise ArgumentError unless artist && track || mbid
56
+ LastFM.requires_authentication
57
+ LastFM.post( "#{TYPE}.getTags", 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
58
+ end
59
+
60
+ # @see http://www.last.fm/api/show?service=312
61
+ def get_top_fans( track = nil, artist = nil, mbid = nil, autocorrect = nil )
62
+ raise ArgumentError unless artist && track || mbid
63
+ LastFM.get( "#{TYPE}.getTopFans", !:secure, 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
64
+ end
65
+
66
+ # @see http://www.last.fm/api/show?service=289
67
+ def get_top_tags( track = nil, artist = nil, mbid = nil, autocorrect = nil )
68
+ raise ArgumentError unless artist && track || mbid
69
+ LastFM.get( "#{TYPE}.getTopTags", !:secure, 'track'=>track, 'artist'=>artist, 'mbid'=>mbid, 'autocorrect'=>autocorrect )
70
+ end
71
+
72
+ # @see http://www.last.fm/api/show?service=260
73
+ def love( track, artist )
74
+ LastFM.requires_authentication
75
+ LastFM.post( "#{TYPE}.love", 'track'=>track, 'artist'=>artist )
76
+ end
77
+
78
+ # @see http://www.last.fm/api/show?service=316
79
+ def remove_tag( track, artist, tag )
80
+ LastFM.requires_authentication
81
+ LastFM.post( "#{TYPE}.removeTag", 'track'=>track, 'artist'=>artist, 'tag'=>tag )
82
+ end
83
+
84
+ # @see http://www.last.fm/api/show?service=443
85
+ def scrobble( tracks, artists, timestamps, albums = nil, album_artists = nil, contexts = nil, stream_ids = nil, track_numbers = nil, mbids = nil, durations = nil )
86
+ LastFM.requires_authentication
87
+ # Requires complicated logic & HTTP POST
88
+ end
89
+
90
+ # @see http://www.last.fm/api/show?service=286
91
+ def search( track, artist = nil, limit = nil, page = nil )
92
+ LastFM.get( "#{TYPE}.search", !:secure, 'track'=>track, 'artist'=>artist, 'limit'=>limit, 'page'=>page )
93
+ end
94
+
95
+ # @see http://www.last.fm/api/show?service=305
96
+ def share( track, artist, recipient, message = nil, public = nil )
97
+ LastFM.requires_authentication
98
+ LastFM.post( "#{TYPE}.share", 'track'=>track, 'artist'=>artist, 'recipient'=>recipient, 'message'=>message, 'public'=>public )
99
+ end
100
+
101
+ # @see http://www.last.fm/api/show?service=449
102
+ def unban( track, artist )
103
+ LastFM.requires_authentication
104
+ LastFM.post( "#{TYPE}.unban", 'track'=>track, 'artist'=>artist )
105
+ end
106
+
107
+ # @see http://www.last.fm/api/show?service=440
108
+ def unlove( track, artist )
109
+ LastFM.requires_authentication
110
+ LastFM.post( "#{TYPE}.unlove", 'track'=>track, 'artist'=>artist )
111
+ end
112
+
113
+ # @see http://www.last.fm/api/show?service=454
114
+ def update_now_playing( track, artist, album = nil, album_artist = nil, context = nil, track_number = nil, mbid = nil, duration = nil )
115
+ LastFM.requires_authentication
116
+ LastFM.post( "#{TYPE}.updateNowPlaying", 'track'=>track, 'artist'=>artist, 'album'=>album, 'albumArtist'=>album_artist, 'context'=>context, 'trackNumber'=>track_number, 'mbid'=>mbid, 'duration'=>duration )
117
+ end
118
+
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,141 @@
1
+ module LastFM
2
+ class User
3
+ class << self
4
+
5
+ TYPE = 'user'
6
+
7
+ # @see http://www.last.fm/api/show?service=432
8
+ def get_artist_tracks( user, artist, start_timestamp = nil, end_timestamp = nil, page = nil )
9
+ LastFM.get( "#{TYPE}.getArtistTracks", !:secure, 'user'=>user, 'artist'=>artist, 'startTimestamp'=>start_timestamp, 'endTimestamp'=>end_timestamp, 'page'=>page )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show?service=448
13
+ def get_banned_tracks( user, limit = nil, page = nil )
14
+ LastFM.get( "#{TYPE}.getBannedTracks", !:secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show?service=291
18
+ def get_events( user, limit = nil, page = nil )
19
+ LastFM.get( "#{TYPE}.getEvents", !:secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
20
+ end
21
+
22
+ # @see http://www.last.fm/api/show?service=263
23
+ def get_friends( user, recent_tracks = nil, limit = nil, page = nil )
24
+ LastFM.get( "#{TYPE}.getFriends", !:secure, 'user'=>user, 'recenttracks'=>recent_tracks, 'limit'=>limit, 'page'=>page )
25
+ end
26
+
27
+ # @see http://www.last.fm/api/show?service=344
28
+ def get_info( user = nil )
29
+ LastFM.get( "#{TYPE}.getInfo", !:secure, 'user'=>user )
30
+ end
31
+
32
+ # @see http://www.last.fm/api/show?service=329
33
+ def get_loved_tracks( user, limit = nil, page = nil )
34
+ LastFM.get( "#{TYPE}.getLovedTracks", !:secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
35
+ end
36
+
37
+ # @see http://www.last.fm/api/show?service=264
38
+ def get_neighbors( user, limit = nil )
39
+ LastFM.get( "#{TYPE}.getNeighbonrs", !:secure, 'user'=>user, 'limit'=>limit )
40
+ end
41
+
42
+ # @see http://www.last.fm/api/show?service=444
43
+ def get_new_releases( user, useresc = nil )
44
+ LastFM.get( "#{TYPE}.getNewReleases", !:secure, 'user'=>user, 'useresc'=>useresc )
45
+ end
46
+
47
+ # @see http://www.last.fm/api/show?service=343
48
+ def get_past_events( user, limit = nil, page = nil )
49
+ LastFM.get( "#{TYPE}.getPastEvents", !:secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
50
+ end
51
+
52
+ @tagging_types = [ 'artist', 'album', 'track' ]
53
+
54
+ # @see http://www.last.fm/api/show?service=455
55
+ def get_personal_tags( user, tag, tagging_type, limit = nil, page = nil )
56
+ raise ArgumentError unless @tagging_types.include?(tagging_type)
57
+ LastFM.get( "#{TYPE}.getPersonalTags", !:secure, 'user'=>user, 'tag'=>tag, 'limit'=>limit, 'page'=>page )
58
+ end
59
+
60
+ # @see http://www.last.fm/api/show?service=313
61
+ def get_playlists( user )
62
+ LastFM.get( "#{TYPE}.getPlaylists", !:secure, 'user'=>user )
63
+ end
64
+
65
+ # @see http://www.last.fm/api/show?service=414
66
+ def get_recent_stations( user, limit = nil, page = nil )
67
+ LastFM.requires_authentication
68
+ LastFM.get( "#{TYPE}.getRecentStations", :secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
69
+ end
70
+
71
+ # @see http://www.last.fm/api/show?service=278
72
+ def get_recent_tracks( user, time_from = nil, time_to = nil, limit = nil, page = nil )
73
+ LastFM.get( "#{TYPE}.getRecentTracks", !:secure, 'user'=>user, 'from'=>time_from, 'to'=>time_to, 'limit'=>limit, 'page'=>page )
74
+ end
75
+
76
+ # @see http://www.last.fm/api/show?service=388
77
+ def get_recommended_artists( limit = nil, page = nil )
78
+ LastFM.requires_authentication
79
+ LastFM.get( "#{TYPE}.getRecommendedArtists", :secure, 'limit'=>limit, 'page'=>page )
80
+ end
81
+
82
+ # @see http://www.last.fm/api/show?service=375
83
+ def get_recommended_events( limit = nil, page = nil )
84
+ LastFM.requires_authentication
85
+ LastFM.get( "#{TYPE}.getRecommendedEvents", :secure, 'limit'=>limit, 'page'=>page )
86
+ end
87
+
88
+ # @see http://www.last.fm/api/show?service=401
89
+ def get_shouts( user, limit = nil, page = nil )
90
+ LastFM.get( "#{TYPE}.getShouts", !:secure, 'user'=>user, 'limit'=>limit, 'page'=>page )
91
+ end
92
+
93
+ # @see http://www.last.fm/api/show?service=299
94
+ def get_top_albums( user, period = nil, limit = nil, page = nil )
95
+ LastFM.get( "#{TYPE}.getTopAlbums", !:secure, 'user'=>user, 'period'=>period, 'limit'=>limit, 'page'=>page )
96
+ end
97
+
98
+ # @see http://www.last.fm/api/show?service=300
99
+ def get_top_artists( user, period = nil, limit = nil, page = nil )
100
+ LastFM.get( "#{TYPE}.getTopArtists", !:secure, 'user'=>user, 'period'=>period, 'limit'=>limit, 'page'=>page )
101
+ end
102
+
103
+ # @see http://www.last.fm/api/show?service=123
104
+ def get_top_tags( user, limit = nil )
105
+ LastFM.get( "#{TYPE}.getTopTags", !:secure, 'user'=>user, 'limit'=>limit )
106
+ end
107
+
108
+ # @see http://www.last.fm/api/show?service=301
109
+ def get_top_tracks( user, period, limit = nil, page = nil )
110
+ LastFM.get( "#{TYPE}.getTopTracks", !:secure, 'user'=>user, 'period'=>period, 'limit'=>limit, 'page'=>page )
111
+ end
112
+
113
+ # @see http://www.last.fm/api/show?service=279
114
+ def get_weekly_album_chart( user, time_from = nil, time_to = nil )
115
+ LastFM.get( "#{TYPE}.getWeeklyAlbumChart", !:secure, 'user'=>user, 'from'=>time_from, 'to'=>time_to )
116
+ end
117
+
118
+ # @see http://www.last.fm/api/show?service=281
119
+ def get_weekly_artist_chart( user, time_from = nil, time_to = nil )
120
+ LastFM.get( "#{TYPE}.getWeeklyArtistChart", !:secure, 'user'=>user, 'from'=>time_from, 'to'=>time_to )
121
+ end
122
+
123
+ # @see http://www.last.fm/api/show?service=280
124
+ def get_weekly_chart_list( user )
125
+ LastFM.get( "#{TYPE}.getWeeklyChartList", !:secure, 'user'=>user )
126
+ end
127
+
128
+ # @see http://www.last.fm/api/show?service=282
129
+ def get_weekly_track_chart( user, time_from = nil, time_to = nil )
130
+ LastFM.get( "#{TYPE}.getWeeklyTrackChart", !:secure, 'user'=>user, 'from'=>time_from, 'to'=>time_to )
131
+ end
132
+
133
+ # @see http://www.last.fm/api/show?service=411
134
+ def shout( user, message )
135
+ LastFM.requires_authentication
136
+ LastFM.post( "#{TYPE}.shout", 'user'=>user, 'message'=>message )
137
+ end
138
+
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,24 @@
1
+ module LastFM
2
+ class Venue
3
+ class << self
4
+
5
+ TYPE = 'venue'
6
+
7
+ # @see http://www.last.fm/api/show?service=394
8
+ def get_events( venue, festivals_only = nil )
9
+ LastFM.get( "#{TYPE}.getEvents", !:secure, 'venue'=>venue, 'festivalsonly'=>festivals_only )
10
+ end
11
+
12
+ # @see http://www.last.fm/api/show?service=395
13
+ def get_past_events( venue, festivals_only = nil, limit = nil, page = nil )
14
+ LastFM.get( "#{TYPE}.getPastEvents", !:secure, 'venue'=>venue, 'festivalsonly'=>festivals_only, 'limit'=>limit, 'page'=>page )
15
+ end
16
+
17
+ # @see http://www.last.fm/api/show?service=396
18
+ def search( venue, country = nil, limit = nil, page = nil )
19
+ LastFM.get( "#{TYPE}.search", !:secure, 'venue'=>venue, 'country'=>country, 'limit'=>limit, 'page'=>page )
20
+ end
21
+
22
+ end
23
+ end
24
+ end
data/lib/rscrobbler.rb ADDED
@@ -0,0 +1,161 @@
1
+ require 'digest/md5'
2
+ require 'libxml'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ $:.unshift(File.dirname(__FILE__))
7
+
8
+ require 'lastfm/album'
9
+ require 'lastfm/artist'
10
+ require 'lastfm/auth'
11
+ require 'lastfm/chart'
12
+ require 'lastfm/event'
13
+ require 'lastfm/geo'
14
+ require 'lastfm/group'
15
+ require 'lastfm/library'
16
+ require 'lastfm/playlist'
17
+ require 'lastfm/radio'
18
+ require 'lastfm/tag'
19
+ require 'lastfm/tasteometer'
20
+ require 'lastfm/track'
21
+ require 'lastfm/user'
22
+ require 'lastfm/venue'
23
+
24
+ module LastFM
25
+ VERSION = '0.0.1'
26
+
27
+ HOST = 'ws.audioscrobbler.com'
28
+ POST_URI = URI.parse("http://#{HOST}/2.0/")
29
+
30
+ class RequestError < StandardError; end
31
+ class AuthenticationError < StandardError; end
32
+
33
+ class << self
34
+
35
+ attr_accessor :api_key, :api_secret, :username, :auth_token
36
+ attr_reader :session_key, :logger
37
+
38
+ # Authenticate the service with provided login credentials. Use mobile
39
+ # authentication to avoid redirecting to the website to log in.
40
+ #
41
+ # @see http://www.last.fm/api/authspec last.fm auth spec
42
+ # @return [String] session key provided from authentication
43
+ def authenticate!
44
+ %w[api_key api_secret username auth_token].each do |cred|
45
+ raise AuthenticationError, "Missing credential: #{cred}" unless LastFM.send(cred)
46
+ end
47
+ @session_key = Auth.get_mobile_session( username, auth_token ).find_first('session/key').content
48
+ end
49
+
50
+ # Has the service been authenticated?
51
+ #
52
+ # @return [Boolean] whether the service has been authenticated
53
+ def authenticated?
54
+ !!session_key
55
+ end
56
+
57
+ # Ensure the service has been authenticated; raise an error if it hasn't.
58
+ #
59
+ # @raise [AuthenticationError] if the service hasn't been authenticated.
60
+ def requires_authentication
61
+ raise AuthenticationError, 'LastFM Authentication Required' unless authenticated?
62
+ end
63
+
64
+ # Generate auth token from username and given password.
65
+ #
66
+ # @param [String] password password to use
67
+ # @return [String] md5 digest of the username and password
68
+ def generate_auth_token( password )
69
+ self.auth_token = Digest::MD5.hexdigest( username.dup << Digest::MD5.hexdigest(password) )
70
+ end
71
+
72
+ # Construct an HTTP GET call from params, and load the response into a LibXML Document.
73
+ #
74
+ # @param [String] method last.fm api method to call
75
+ # @param [optional, Boolean] secure whether sign the request with a method signature and session key
76
+ # (one exception being auth methods, which require a method signature but no session key)
77
+ # @param [Hash] params parameters to send, excluding method, api_key, api_sig, and sk
78
+ # @return [LibXML::XML::Document] xml document of the data contained in the response
79
+ # @raise [LastFMError] if the request fails
80
+ def get( method, secure = false, params = {} )
81
+ path = generate_path(method, secure, params)
82
+ logger.debug( "Last.fm HTTP GET: #{HOST+path}" ) if logger
83
+ response = Net::HTTP.get_response( HOST, path )
84
+ check_status( LibXML::XML::Parser.string( response.body ).parse )
85
+ end
86
+
87
+ # Construct an HTTP POST call from params, and check the response status.
88
+ #
89
+ # @param [String] method last.fm api method to call
90
+ # @param [Hash] params parameters to send, excluding method, api_key, api_sig, and sk
91
+ # @return [LibXML::XML::Document] xml document of the data contained in the response
92
+ # @raise [LastFMError] if the request fails
93
+ def post( method, params )
94
+ params = construct_params( method, :secure, params )
95
+ logger.debug( "Last.fm HTTP POST: #{POST_URI}, #{params.to_s}" ) if logger
96
+ response = Net::HTTP.post_form( POST_URI, params )
97
+ check_status( LibXML::XML::Parser.string( response.body ).parse )
98
+ end
99
+
100
+ private
101
+
102
+ # Check an XML document for status = failed, and throw a descriptive error if it's found.
103
+ #
104
+ # @param [LibXML::XML::Document] xml xml document to check for errors
105
+ # @return [LibXML::XML::Document] the xml document if no errors were found
106
+ # @raise [LastFMError] if an error is found
107
+ # @private
108
+ def check_status( xml )
109
+ raise RequestError, xml.find_first('error').content if xml.root.attributes['status'] == 'failed'
110
+ xml
111
+ end
112
+
113
+ # Normalize the parameter list by converting values to a string and removing any nils. Add method,
114
+ # api key, session key, and api signature parameters where necessary.
115
+ #
116
+ # @param [String] method last.fm api method
117
+ # @param [Boolean] secure whether to include session key and api signature in the parameters
118
+ # @param [Hash] params parameters to normalize and add to
119
+ # @return [Hash] complete, normalized parameters
120
+ def construct_params( method, secure, params )
121
+ params.delete_if{|k,v| v.nil? }
122
+ params.each{|k,v| params[k] = params[k].to_s }
123
+ params['method'] = method
124
+ params['api_key'] = api_key
125
+ params['sk'] = session_key if authenticated? && secure
126
+ params['api_sig'] = generate_method_signature( params ) if secure
127
+ params
128
+ end
129
+
130
+ # Generate the path for a particular method call given params.
131
+ #
132
+ # @param [String] method last.fm method to call
133
+ # @param [Boolean] secure whether to include session key and api signature in the call
134
+ # @param [optional, Hash] params parameters to include in the api call
135
+ # @return [String] path for the api call
136
+ # @private
137
+ def generate_path( method, secure, params={} )
138
+ params = construct_params( method, secure, params )
139
+ url = "/2.0/?method=#{params.delete('method')}"
140
+ params.keys.each do |key|
141
+ url << "&#{key}=#{params[key]}"
142
+ end
143
+ URI.encode(url)
144
+ end
145
+
146
+ # Generate a method signature based on given parameters.
147
+ #
148
+ # @param [Hash] parameters to combine into a method signature
149
+ # @return [String] method signature based on all the parameters
150
+ # @see http://www.last.fm/api/authspec#8
151
+ # @private
152
+ def generate_method_signature( params )
153
+ str = ''
154
+ params.keys.sort.each do |key|
155
+ str << key << params[key]
156
+ end
157
+ Digest::MD5.hexdigest( str << api_secret )
158
+ end
159
+
160
+ end
161
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rscrobbler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gabe Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: libxml-ruby
16
+ requirement: &2160394600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2160394600
25
+ description: rscrobbler is a Ruby gem for accessing Last.fm's API (http://www.last.fm/api).
26
+ email:
27
+ - sgt.floydpepper@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/lastfm/album.rb
33
+ - lib/lastfm/artist.rb
34
+ - lib/lastfm/auth.rb
35
+ - lib/lastfm/chart.rb
36
+ - lib/lastfm/event.rb
37
+ - lib/lastfm/geo.rb
38
+ - lib/lastfm/group.rb
39
+ - lib/lastfm/library.rb
40
+ - lib/lastfm/playlist.rb
41
+ - lib/lastfm/radio.rb
42
+ - lib/lastfm/tag.rb
43
+ - lib/lastfm/tasteometer.rb
44
+ - lib/lastfm/track.rb
45
+ - lib/lastfm/user.rb
46
+ - lib/lastfm/venue.rb
47
+ - lib/rscrobbler.rb
48
+ homepage: https://github.com/sgtFloyd/rscrobbler
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.12
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Last.fm API wrapper
72
+ test_files: []