lastfm 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/README.rdoc +24 -11
  2. data/VERSION +1 -1
  3. data/lib/lastfm.rb +25 -15
  4. data/lib/lastfm/method_category/artist.rb +9 -0
  5. data/lib/lastfm/method_category/event.rb +9 -0
  6. data/lib/lastfm/method_category/tag.rb +9 -0
  7. data/lib/lastfm/method_category/user.rb +34 -17
  8. data/spec/fixtures/album_get_info.xml +168 -157
  9. data/spec/fixtures/artist_get_events.xml +13 -13
  10. data/spec/fixtures/artist_get_info.xml +93 -93
  11. data/spec/fixtures/artist_get_similar.xml +12 -0
  12. data/spec/fixtures/artist_get_tags.xml +13 -0
  13. data/spec/fixtures/event_get_info.xml +39 -0
  14. data/spec/fixtures/geo_get_events.xml +4 -4
  15. data/spec/fixtures/library_get_artists.xml +1 -0
  16. data/spec/fixtures/library_get_tracks.xml +15 -14
  17. data/spec/fixtures/ng.xml +2 -1
  18. data/spec/fixtures/ok.xml +87 -102
  19. data/spec/fixtures/tag_get_top_artists.xml +60 -0
  20. data/spec/fixtures/track_get_correction.xml +2 -1
  21. data/spec/fixtures/track_get_info.xml +47 -53
  22. data/spec/fixtures/track_get_info_force_array.xml +28 -31
  23. data/spec/fixtures/track_get_similar.xml +75 -5078
  24. data/spec/fixtures/track_get_tags.xml +10 -10
  25. data/spec/fixtures/track_get_top_fans.xml +23 -26
  26. data/spec/fixtures/track_get_top_tags.xml +13 -13
  27. data/spec/fixtures/track_search.xml +31 -33
  28. data/spec/fixtures/user_get_friends.xml +2 -1
  29. data/spec/fixtures/user_get_info.xml +2 -1
  30. data/spec/fixtures/user_get_loved_tracks.xml +23 -22
  31. data/spec/fixtures/user_get_neighbours.xml +54 -502
  32. data/spec/fixtures/user_get_personal_tags.xml +29 -0
  33. data/spec/fixtures/user_get_personal_tags_albums.xml +21 -0
  34. data/spec/fixtures/user_get_personal_tags_artists.xml +62 -0
  35. data/spec/fixtures/user_get_personal_tags_tracks.xml +87 -0
  36. data/spec/fixtures/user_get_recent_tracks.xml +2 -1
  37. data/spec/fixtures/user_get_top_albums.xml +22 -22
  38. data/spec/fixtures/user_get_top_artists.xml +22 -22
  39. data/spec/fixtures/user_get_top_tags.xml +30 -0
  40. data/spec/fixtures/user_get_top_tracks.xml +24 -23
  41. data/spec/lastfm_spec.rb +33 -516
  42. data/spec/method_specs/album_spec.rb +30 -0
  43. data/spec/method_specs/artist_spec.rb +79 -0
  44. data/spec/method_specs/event_spec.rb +17 -0
  45. data/spec/method_specs/geo_spec.rb +33 -0
  46. data/spec/method_specs/library_spec.rb +37 -0
  47. data/spec/method_specs/tag_spec.rb +25 -0
  48. data/spec/method_specs/track_spec.rb +224 -0
  49. data/spec/method_specs/user_spec.rb +214 -0
  50. data/spec/response_spec.rb +4 -4
  51. data/spec/spec_helper.rb +15 -0
  52. data/spec/util_spec.rb +4 -4
  53. metadata +34 -15
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#album' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::Album' do
7
+ @lastfm.album.should be_an_instance_of(Lastfm::MethodCategory::Album)
8
+ end
9
+
10
+ describe '#get_info' do
11
+ it 'should get info' do
12
+ @lastfm.should_receive(:request).with('album.getInfo', {
13
+ :artist => 'Cher', :album => 'Believe'
14
+ }).and_return(make_response('album_get_info'))
15
+
16
+ album = @lastfm.album.get_info('Cher', 'Believe')
17
+ album['name'].should == 'Believe'
18
+ album['artist'].should == 'Cher'
19
+ album['id'].should == '2026126'
20
+ album['mbid'].should == '61bf0388-b8a9-48f4-81d1-7eb02706dfb0'
21
+ album['url'].should == 'http://www.last.fm/music/Cher/Believe'
22
+ album['image'].size.should == 5
23
+ album['releasedate'].should == '6 Apr 1999, 00:00'
24
+ album['tracks']['track'].size.should == 10
25
+ album['tracks']['track'][0]['name'].should == 'Believe'
26
+ album['tracks']['track'][0]['duration'].should == '239'
27
+ album['tracks']['track'][0]['url'].should == 'http://www.last.fm/music/Cher/_/Believe'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,79 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#artist' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::Artist' do
7
+ @lastfm.artist.should be_an_instance_of(Lastfm::MethodCategory::Artist)
8
+ end
9
+
10
+ describe '#get_info' do
11
+ it 'should get info' do
12
+ @lastfm.should_receive(:request).with('artist.getInfo', {
13
+ :artist => 'Cher'
14
+ }).and_return(make_response('artist_get_info'))
15
+
16
+ artist = @lastfm.artist.get_info('Cher')
17
+ artist['name'].should == 'Cher'
18
+ artist['mbid'].should == 'bfcc6d75-a6a5-4bc6-8282-47aec8531818'
19
+ artist['url'].should == 'http://www.last.fm/music/Cher'
20
+ artist['image'].size.should == 5
21
+ end
22
+ end
23
+
24
+ describe '#get_events' do
25
+ it 'should get events' do
26
+ @lastfm.should_receive(:request).with('artist.getEvents', {
27
+ :artist => 'Cher'
28
+ }).and_return(make_response('artist_get_events'))
29
+
30
+ events = @lastfm.artist.get_events('Cher')
31
+ events.size.should == 1
32
+ events[0]['title'].should == 'Cher'
33
+ events[0]['artists'].size.should == 2
34
+ events[0]['artists']['headliner'].should == 'Cher'
35
+ events[0]['venue']['name'].should == 'The Colosseum At Caesars Palace'
36
+ events[0]['venue']['location']['city'].should == 'Las Vegas(, NV)'
37
+ events[0]['venue']['location']['point']['lat'].should == '36.116143'
38
+ events[0]['image'].size.should == 4
39
+ events[0]['image'][0]['size'].should == 'small'
40
+ events[0]['image'][0]['content'].should == 'http://userserve-ak.last.fm/serve/34/34814037.jpg'
41
+ events[0]['startDate'].should == 'Sat, 23 Oct 2010 19:30:00'
42
+ events[0]['tickets']['ticket']['supplier'].should == 'TicketMaster'
43
+ events[0]['tickets']['ticket']['content'].should == 'http://www.last.fm/affiliate/byid/29/1584537/12/ws.artist.events.b25b959554ed76058ac220b7b2e0a026'
44
+ events[0]['tags']['tag'].should == ['pop', 'dance', 'female vocalists', '80s', 'cher']
45
+ end
46
+ end
47
+
48
+ describe '#get_similar' do
49
+ it 'should get similar artists' do
50
+ @lastfm.should_receive(:request).with('artist.getSimilar', {
51
+ :artist => 'kid606'
52
+ }).and_return(make_response('artist_get_similar'))
53
+
54
+ artists = @lastfm.artist.get_similar('kid606')
55
+ artists.size.should == 2
56
+ artists[1]['name'].should == 'Venetian Snares'
57
+ artists[1]['mbid'].should == '56abaa47-0101-463b-b37e-e961136fec39'
58
+ artists[1]['match'].should == '100'
59
+ artists[1]['url'].should == '/music/Venetian+Snares'
60
+ artists[1]['image'].should == ['http://userserve-ak.last.fm/serve/160/211799.jpg']
61
+ end
62
+ end
63
+
64
+ describe '#get_tags' do
65
+ it 'should get artist tags' do
66
+ @lastfm.should_receive(:request).with('artist.getTags', {
67
+ :artist => 'zebrahead',
68
+ :user => 'test',
69
+ :mbid => nil,
70
+ :autocorrect => nil
71
+ }).and_return(make_response('artist_get_tags'))
72
+
73
+ tags = @lastfm.artist.get_tags('zebrahead', 'test')
74
+ tags.size.should == 2
75
+ tags[0]['name'].should == 'punk'
76
+ tags[1]['name'].should == 'Awesome'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,17 @@
1
+ describe '#event' do
2
+ before { init_lastfm }
3
+
4
+ it 'should return an instance of Lastfm::Event' do
5
+ @lastfm.event.should be_an_instance_of(Lastfm::MethodCategory::Event)
6
+ end
7
+
8
+ describe '#get_info' do
9
+ it 'should get info' do
10
+ @lastfm.should_receive(:request).with('event.getInfo', {
11
+ :event => 1073657
12
+ }).and_return(make_response('event_get_info'))
13
+ info = @lastfm.event.get_info(1073657)
14
+ info['title'].should == 'Neko Case'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#geo' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::Geo' do
7
+ @lastfm.geo.should be_an_instance_of(Lastfm::MethodCategory::Geo)
8
+ end
9
+
10
+ describe '#get_events' do
11
+ it 'should get events' do
12
+ @lastfm.should_receive(:request).with('geo.getEvents', {
13
+ :location => 'Boulder',
14
+ :distance => nil,
15
+ :limit => nil,
16
+ :page => nil
17
+ }).and_return(make_response('geo_get_events'))
18
+
19
+ events = @lastfm.geo.get_events('Boulder')
20
+ events.size.should == 1
21
+ events[0]['title'].should == 'Transistor Festival'
22
+ events[0]['artists'].size.should == 2
23
+ events[0]['artists']['headliner'].should == 'Not Breathing'
24
+ events[0]['venue']['name'].should == 'The Walnut Room'
25
+ events[0]['venue']['location']['city'].should == 'Denver, CO'
26
+ events[0]['venue']['location']['point']['lat'].should == '39.764316'
27
+ events[0]['image'].size.should == 4
28
+ events[0]['image'][0]['size'].should == 'small'
29
+ events[0]['image'][0]['content'].should == 'http://userserve-ak.last.fm/serve/34/166214.jpg'
30
+ events[0]['startDate'].should == 'Fri, 10 Jun 2011 01:58:01'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#library' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::Library' do
7
+ @lastfm.library.should be_an_instance_of(Lastfm::MethodCategory::Library)
8
+ end
9
+
10
+ describe '#get_tracks' do
11
+ it 'should get the tracks\' info' do
12
+ @lastfm.should_receive(:request).with('library.getTracks', {
13
+ :user => 'test',
14
+ :artist => 'foo',
15
+ :album => 'bar',
16
+ :limit => nil,
17
+ :page => nil
18
+ }).and_return(make_response('library_get_tracks'))
19
+ tracks = @lastfm.library.get_tracks('test', 'foo', 'bar')
20
+ tracks[0]['name'].should == 'Learning to Live'
21
+ tracks.size.should == 1
22
+ end
23
+ end
24
+
25
+ describe '#get_artists' do
26
+ it 'should get the artists\' info' do
27
+ @lastfm.should_receive(:request).with('library.getArtists', {
28
+ :user => 'test',
29
+ :limit => nil,
30
+ :page => nil
31
+ }).and_return(make_response('library_get_artists'))
32
+ artists = @lastfm.library.get_artists('test')
33
+ artists[1]['name'].should == 'Dark Castle'
34
+ artists.size.should == 2
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#tag' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::Tag' do
7
+ @lastfm.tag.should be_an_instance_of(Lastfm::MethodCategory::Tag)
8
+ end
9
+
10
+ describe '#get_top_artists' do
11
+ it 'should get top artists of some tag' do
12
+ @lastfm.should_receive(:request).with('tag.getTopArtists', {
13
+ :tag => 'Disco',
14
+ :limit => nil,
15
+ :page => nil
16
+ }).and_return(make_response('tag_get_top_artists'))
17
+
18
+ artists = @lastfm.tag.get_top_artists('Disco')
19
+ artists.size.should == 5
20
+ artists[0]['name'].should == 'Bee Gees'
21
+ artists[0]['url'].should == 'http://www.last.fm/music/Bee+Gees'
22
+ artists[1]['name'].should == 'ABBA'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,224 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#track' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::Track' do
7
+ @lastfm.track.should be_an_instance_of(Lastfm::MethodCategory::Track)
8
+ end
9
+
10
+ describe '#add_tags' do
11
+ it 'should add tags' do
12
+ @lastfm.should_receive(:request).with('track.addTags', {
13
+ :artist => 'foo artist',
14
+ :track => 'foo track',
15
+ :tags => 'aaa,bbb,ccc'
16
+ }, :post, true, true).and_return(@ok_response)
17
+
18
+ @lastfm.track.add_tags('foo artist', 'foo track', 'aaa,bbb,ccc').should be_true
19
+ end
20
+ end
21
+
22
+ describe '#ban' do
23
+ it 'should ban' do
24
+ @lastfm.should_receive(:request).with('track.ban', {
25
+ :artist => 'foo artist',
26
+ :track => 'foo track',
27
+ }, :post, true, true).and_return(@ok_response)
28
+
29
+ @lastfm.track.ban('foo artist', 'foo track').should be_true
30
+ end
31
+ end
32
+
33
+ describe '#get_info' do
34
+ it 'should get info' do
35
+ @lastfm.should_receive(:request).with('track.getInfo', {
36
+ :artist => 'Cher',
37
+ :track => 'Believe',
38
+ :username => 'youpy',
39
+ }).and_return(make_response('track_get_info'))
40
+
41
+ track = @lastfm.track.get_info('Cher', 'Believe', 'youpy')
42
+ track['name'].should == 'Believe'
43
+ track['album']['image'].size.should == 4
44
+ track['album']['image'].first['size'].should == 'small'
45
+ track['album']['image'].first['content'].should == 'http://userserve-ak.last.fm/serve/64s/8674593.jpg'
46
+ track['toptags']['tag'].size.should == 5
47
+ track['toptags']['tag'].first['name'].should == 'pop'
48
+ end
49
+
50
+ it 'should get xml with force array option' do
51
+ @lastfm.should_receive(:request).with('track.getInfo', {
52
+ :artist => 'Cher',
53
+ :track => 'Believe',
54
+ :username => 'youpy',
55
+ }).and_return(make_response('track_get_info_force_array'))
56
+
57
+ track = @lastfm.track.get_info('Cher', 'Believe', 'youpy')
58
+ track['album']['image'].size.should == 1
59
+ track['album']['image'].first['size'].should == 'small'
60
+ track['album']['image'].first['content'].should == 'http://userserve-ak.last.fm/serve/64s/8674593.jpg'
61
+ track['toptags']['tag'].size.should == 1
62
+ track['toptags']['tag'].first['name'].should == 'pop'
63
+ end
64
+ end
65
+
66
+ describe '#get_correction' do
67
+ it 'should get correction' do
68
+ @lastfm.should_receive(:request).with('track.getCorrection', {
69
+ :artist => 'White Stripes',
70
+ :track => 'One More Cup of Coffee',
71
+ :username => 'wainekerr',
72
+ }).and_return(make_response('track_get_correction'))
73
+
74
+ correction = @lastfm.track.get_correction('White Stripes', 'One More Cup of Coffee', 'wainekerr')
75
+ correction['track']['name'].should == 'One More Cup of Coffee'
76
+ correction['track']['artist']['name'].should == 'The White Stripes'
77
+ correction['track']['url'].should == 'www.last.fm/music/The+White+Stripes/_/One+More+Cup+of+Coffee'
78
+ end
79
+ end
80
+
81
+ describe '#get_similar' do
82
+ it 'should get similar' do
83
+ @lastfm.should_receive(:request).with('track.getSimilar', {
84
+ :artist => 'Cher',
85
+ :track => 'Believe',
86
+ }).and_return(make_response('track_get_similar'))
87
+
88
+ tracks = @lastfm.track.get_similar('Cher', 'Believe')
89
+ tracks.size.should == 5
90
+ tracks.first['name'].should == 'Strong Enough'
91
+ tracks.first['image'][1]['content'].should == 'http://userserve-ak.last.fm/serve/64s/8674593.jpg'
92
+ tracks[1]['image'][0]['content'].should == 'http://userserve-ak.last.fm/serve/34s/8674593.jpg'
93
+ end
94
+ end
95
+
96
+ describe '#get_tags' do
97
+ it 'should get tags' do
98
+ @lastfm.should_receive(:request).with('track.getTags', {
99
+ :artist => 'foo artist',
100
+ :track => 'foo track',
101
+ }, :get, true, true).and_return(make_response('track_get_tags'))
102
+
103
+ tags = @lastfm.track.get_tags('foo artist', 'foo track')
104
+ tags.size.should == 2
105
+ tags[0]['name'].should == 'swedish'
106
+ tags[0]['url'].should == 'http://www.last.fm/tag/swedish'
107
+ end
108
+ end
109
+
110
+ describe '#get_top_fans' do
111
+ it 'should get top fans' do
112
+ @lastfm.should_receive(:request).with('track.getTopFans', {
113
+ :artist => 'foo artist',
114
+ :track => 'foo track',
115
+ }).and_return(make_response('track_get_top_fans'))
116
+
117
+ users = @lastfm.track.get_top_fans('foo artist', 'foo track')
118
+ users.size.should == 2
119
+ users[0]['name'].should == 'Through0glass'
120
+ end
121
+ end
122
+
123
+ describe '#get_top_tags' do
124
+ it 'should get top tags' do
125
+ @lastfm.should_receive(:request).with('track.getTopTags', {
126
+ :artist => 'foo artist',
127
+ :track => 'foo track',
128
+ }).and_return(make_response('track_get_top_tags'))
129
+
130
+ tags = @lastfm.track.get_top_tags('foo artist', 'foo track')
131
+ tags.size.should == 2
132
+ tags[0]['name'].should == 'alternative'
133
+ tags[0]['count'].should == '100'
134
+ tags[0]['url'].should == 'www.last.fm/tag/alternative'
135
+ end
136
+ end
137
+
138
+ describe '#love' do
139
+ it 'should love' do
140
+ @lastfm.should_receive(:request).with('track.love', {
141
+ :artist => 'foo artist',
142
+ :track => 'foo track',
143
+ }, :post, true, true).and_return(@ok_response)
144
+
145
+ @lastfm.track.love('foo artist', 'foo track').should be_true
146
+ end
147
+ end
148
+
149
+ describe '#remove_tag' do
150
+ it 'should remove tag' do
151
+ @lastfm.should_receive(:request).with('track.removeTag', {
152
+ :artist => 'foo artist',
153
+ :track => 'foo track',
154
+ :tag => 'aaa'
155
+ }, :post, true, true).and_return(@ok_response)
156
+
157
+ @lastfm.track.remove_tag('foo artist', 'foo track', 'aaa').should be_true
158
+ end
159
+ end
160
+
161
+ describe '#search' do
162
+ it 'should search' do
163
+ @lastfm.should_receive(:request).with('track.search', {
164
+ :artist => nil,
165
+ :track => 'Believe',
166
+ :limit => 10,
167
+ :page => 3,
168
+ }).and_return(make_response('track_search'))
169
+
170
+ tracks = @lastfm.track.search('Believe', nil, 10, 3)
171
+ tracks['results']['for'].should == 'Believe'
172
+ tracks['results']['totalResults'].should == '40540'
173
+ tracks['results']['trackmatches']['track'].size.should == 2
174
+ tracks['results']['trackmatches']['track'][0]['name'].should == 'Make Me Believe'
175
+ end
176
+ end
177
+
178
+ describe '#share' do
179
+ it 'should share' do
180
+ @lastfm.should_receive(:request).with('track.share', {
181
+ :artist => 'foo artist',
182
+ :track => 'foo track',
183
+ :message => 'this is a message',
184
+ :recipient => 'foo@example.com',
185
+ }, :post, true, true).and_return(@ok_response)
186
+
187
+ @lastfm.track.share('foo artist', 'foo track', 'foo@example.com', 'this is a message').should be_true
188
+ end
189
+ end
190
+
191
+ describe '#scrobble' do
192
+ it 'should scrobble' do
193
+ time = Time.now
194
+ @lastfm.should_receive(:request).with('track.scrobble', {
195
+ :artist => 'foo artist',
196
+ :track => 'foo track',
197
+ :album => 'foo album',
198
+ :mbid => '0383dadf-2a4e-4d10-a46a-e9e041da8eb3',
199
+ :timestamp => time,
200
+ :trackNumber => 1,
201
+ :duration => nil,
202
+ :albumArtist => nil,
203
+ }, :post, true, true).and_return(@ok_response)
204
+
205
+ @lastfm.track.scrobble('foo artist', 'foo track', time, 'foo album', 1, '0383dadf-2a4e-4d10-a46a-e9e041da8eb3', nil, nil)
206
+ end
207
+ end
208
+
209
+ describe '#update_now_playing' do
210
+ it 'should update now playing' do
211
+ @lastfm.should_receive(:request).with('track.updateNowPlaying', {
212
+ :artist => 'foo artist',
213
+ :track => 'foo track',
214
+ :album => 'foo album',
215
+ :mbid => '0383dadf-2a4e-4d10-a46a-e9e041da8eb3',
216
+ :trackNumber => 1,
217
+ :duration => nil,
218
+ :albumArtist => nil,
219
+ }, :post, true, true).and_return(@ok_response)
220
+
221
+ @lastfm.track.update_now_playing('foo artist', 'foo track', 'foo album', 1, '0383dadf-2a4e-4d10-a46a-e9e041da8eb3', nil, nil)
222
+ end
223
+ end
224
+ end