lastfm 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/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,214 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe '#user' do
4
+ before { init_lastfm }
5
+
6
+ it 'should return an instance of Lastfm::User' do
7
+ @lastfm.user.should be_an_instance_of(Lastfm::MethodCategory::User)
8
+ end
9
+
10
+ describe '#get_info' do
11
+ it 'should get user info' do
12
+ @lastfm.should_receive(:request).with('user.getInfo', {:user => 'test'}).and_return(make_response('user_get_info'))
13
+ info = @lastfm.user.get_info('test')
14
+ info['id'].should == '1000002'
15
+ end
16
+ end
17
+
18
+ describe '#get_top_artists' do
19
+ it 'should get user\'s top artists' do
20
+ @lastfm.should_receive(:request).with('user.getTopArtists', {
21
+ :user => 'test',
22
+ :period => 'overall',
23
+ :limit => nil,
24
+ :page => nil
25
+ }).and_return(make_response('user_get_top_artists'))
26
+
27
+ artists = @lastfm.user.get_top_artists('test', 'overall', nil, nil)
28
+
29
+ artists.size.should == 3
30
+ artists[0]['name'].should == 'Pain of Salvation'
31
+ artists[0]['playcount'].should == '1354'
32
+
33
+ artists[1]['name'].should == 'Opeth'
34
+ artists[1]['playcount'].should == '1186'
35
+
36
+ artists[2]['name'].should == 'Nevermore'
37
+ artists[2]['playcount'].should == '959'
38
+ end
39
+ end
40
+
41
+ describe '#get_personal_tags' do
42
+ it 'should get user\'s tagged artists' do
43
+ @lastfm.should_receive(:request).with('user.getPersonalTags', {
44
+ :user => 'test',
45
+ :tag => 'rock',
46
+ :taggingtype => 'artist',
47
+ :limit => nil,
48
+ :page => nil
49
+ }).and_return(make_response('user_get_personal_tags_artists'))
50
+
51
+ artists = @lastfm.user.get_personal_tags('test', 'rock')
52
+ artists[0]['name'].should == 'Afghan Whigs'
53
+ artists[0]['url'].should == 'http://www.last.fm/music/Afghan+Whigs'
54
+ artists[1]['name'].should == 'Jeff The Brotherhood'
55
+ artists.size.should == 5
56
+ end
57
+
58
+ it 'should get user\'s tagged albums' do
59
+ @lastfm.should_receive(:request).with('user.getPersonalTags', {
60
+ :user => 'test',
61
+ :tag => 'hip-hop',
62
+ :taggingtype => 'album',
63
+ :limit => nil,
64
+ :page => nil
65
+ }).and_return(make_response('user_get_personal_tags_albums'))
66
+
67
+ albums = @lastfm.user.get_personal_tags('test', 'hip-hop', 'album')
68
+ albums[0]['name'].should == 'DJ Bizkid Presents: The Best of Atmosphere'
69
+ albums.size.should == 1
70
+ end
71
+
72
+ it 'should get user\'s tagged tracks' do
73
+ @lastfm.should_receive(:request).with('user.getPersonalTags', {
74
+ :user => 'test',
75
+ :tag => 'jazz',
76
+ :taggingtype => 'track',
77
+ :limit => nil,
78
+ :page => nil
79
+ }).and_return(make_response('user_get_personal_tags_tracks'))
80
+
81
+ tracks = @lastfm.user.get_personal_tags('test', 'jazz', 'track')
82
+ tracks[0]['name'].should == 'Come Together'
83
+ tracks[1]['name'].should == 'Dione'
84
+ tracks[1]['duration'].should == '450'
85
+ tracks.size.should == 5
86
+ end
87
+ end
88
+
89
+ describe '#get_top_albums' do
90
+ it 'should get user\'s top albums' do
91
+ @lastfm.should_receive(:request).with('user.getTopAlbums', {
92
+ :user => 'test',
93
+ :period => 'overall',
94
+ :limit => nil,
95
+ :page => nil
96
+ }).and_return(make_response('user_get_top_albums'))
97
+
98
+ albums = @lastfm.user.get_top_albums('test', 'overall', nil, nil)
99
+
100
+ albums.size.should == 2
101
+
102
+ albums[0]['rank'].should == '1'
103
+ albums[0]['name'].should == 'The Wall'
104
+ albums[0]['artist']['name'].should == 'Pink Floyd'
105
+
106
+ albums[1]['rank'].should == '2'
107
+ albums[1]['name'].should == 'The Perfect Element, Part I'
108
+ albums[1]['artist']['name'].should == 'Pain of Salvation'
109
+ end
110
+ end
111
+
112
+ describe '#get_top_tracks' do
113
+ it 'should get user\'s top tracks' do
114
+ @lastfm.should_receive(:request).with('user.getTopTracks', {
115
+ :user => 'test',
116
+ :period => '7day',
117
+ :limit => nil,
118
+ :page => nil
119
+ }).and_return(make_response('user_get_top_tracks'))
120
+
121
+ tracks = @lastfm.user.get_top_tracks('test', '7day', nil, nil)
122
+
123
+ tracks.size.should == 2
124
+
125
+ tracks[0]['rank'].should == '1'
126
+ tracks[0]['name'].should == 'No Light, No Light (TV On The Radio Remix)'
127
+ tracks[0]['artist']['name'].should == 'Florence + the Machine'
128
+
129
+ tracks[1]['rank'].should == '2'
130
+ tracks[1]['name'].should == 'Backwords (Porcelain Raft cover)'
131
+ tracks[1]['artist']['name'].should == 'Oupa & Tony Crow'
132
+ end
133
+ end
134
+
135
+ describe '#get_loved_tracks' do
136
+ it 'should get user\'s loved tracks' do
137
+ @lastfm.should_receive(:request).with('user.getLovedTracks', {
138
+ :user => 'test',
139
+ :period => nil,
140
+ :limit => nil,
141
+ :page => nil
142
+ }).and_return(make_response('user_get_loved_tracks'))
143
+
144
+ tracks = @lastfm.user.get_loved_tracks('test', nil, nil, nil)
145
+
146
+ tracks.size.should == 2
147
+
148
+ tracks[0]['rank'].should == nil
149
+ tracks[0]['name'].should == 'I Spy'
150
+ tracks[0]['artist']['name'].should == 'Mikhael Paskalev'
151
+
152
+ tracks[1]['rank'].should == nil
153
+ tracks[1]['name'].should == 'Working Titles'
154
+ tracks[1]['artist']['name'].should == 'Damien Jurado'
155
+ end
156
+ end
157
+
158
+ describe '#get_friends' do
159
+ it 'should get user\'s friends' do
160
+ @lastfm.should_receive(:request).with('user.getFriends', {
161
+ :user => 'test',
162
+ :recenttracks => nil,
163
+ :page => nil,
164
+ :limit => nil
165
+ }).and_return(make_response('user_get_friends'))
166
+ friends = @lastfm.user.get_friends('test')
167
+ friends.size.should == 1
168
+ friends[0]['name'].should == 'polaroide'
169
+ end
170
+ end
171
+
172
+ describe '#get_neighbours' do
173
+ it 'should get user\'s neighbours' do
174
+ @lastfm.should_receive(:request).with('user.getNeighbours', {
175
+ :user => 'rj',
176
+ :recenttracks => nil,
177
+ :page => nil,
178
+ :limit => nil
179
+ }).and_return(make_response('user_get_neighbours'))
180
+ neighbours = @lastfm.user.get_neighbours('rj')
181
+ neighbours.size.should == 5
182
+ neighbours[0]['name'].should == 'willywongi'
183
+ end
184
+ end
185
+
186
+ describe '#get_recent_tracks' do
187
+ it 'should get user\'s recent tracks' do
188
+ @lastfm.should_receive(:request).with('user.getRecentTracks', {
189
+ :user => 'test',
190
+ :page => nil,
191
+ :limit => nil,
192
+ :to => nil,
193
+ :from => nil
194
+ }).and_return(make_response('user_get_recent_tracks'))
195
+ tracks = @lastfm.user.get_recent_tracks('test')
196
+ tracks[1]['artist']['content'].should == 'Kylie Minogue'
197
+ tracks.size.should == 2
198
+ end
199
+ end
200
+
201
+ describe '#get_top_tags' do
202
+ it 'should get user\'s top tags' do
203
+ @lastfm.should_receive(:request).with('user.getTopTags', {
204
+ :user => 'test',
205
+ :limit => nil
206
+ }).and_return(make_response('user_get_top_tags'))
207
+ tags = @lastfm.user.get_top_tags('test')
208
+ tags[0]['name'].should == 'rock'
209
+ tags[0]['count'].should == '19'
210
+ tags[1]['count'].should == '15'
211
+ tags.size.should == 5
212
+ end
213
+ end
214
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "Lastfm::Response" do
3
+ describe 'Lastfm::Response' do
4
4
  before do
5
5
  @ok = open(fixture('ok.xml')).read
6
6
  @ng = open(fixture('ng.xml')).read
@@ -23,7 +23,7 @@ describe "Lastfm::Response" do
23
23
 
24
24
  it 'should parse response body as xml' do
25
25
  xml = @response.xml
26
- xml['similartracks']['track'].size.should eql(7)
26
+ xml['similartracks']['track'].size.should == 7
27
27
  end
28
28
  end
29
29
 
@@ -37,11 +37,11 @@ describe "Lastfm::Response" do
37
37
  end
38
38
 
39
39
  it 'should have message' do
40
- @response.message.should eql('Invalid API key - You must be granted a valid key by last.fm')
40
+ @response.message.should == 'Invalid API key - You must be granted a valid key by last.fm'
41
41
  end
42
42
 
43
43
  it 'should have error number' do
44
- @response.error.should eql(10)
44
+ @response.error.should == 10
45
45
  end
46
46
  end
47
47
  end
data/spec/spec_helper.rb CHANGED
@@ -12,4 +12,19 @@ RSpec.configure do |config|
12
12
 
13
13
  Lastfm::Response.new(xml_filename_or_string)
14
14
  end
15
+
16
+ def init_lastfm
17
+ @lastfm = Lastfm.new('xxx', 'yyy')
18
+ @response_xml = <<XML
19
+ <?xml version="1.0" encoding="utf-8"?>
20
+ <lfm status="ok">
21
+ <foo>bar</foo></lfm>
22
+ XML
23
+ ok_response_xml = <<XML
24
+ <?xml version="1.0" encoding="utf-8"?>
25
+ <lfm status="ok">
26
+ </lfm>
27
+ XML
28
+ @ok_response = make_response(ok_response_xml)
29
+ end
15
30
  end
data/spec/util_spec.rb CHANGED
@@ -11,11 +11,11 @@ describe Lastfm::Util do
11
11
  ['foo', nil],
12
12
  [:foo],
13
13
  [[:bar, 'xxx'], [:baz, nil]
14
- ]).should eql({
14
+ ]).should == {
15
15
  :foo => 'foo',
16
16
  :bar => 'xxx',
17
17
  :baz => nil,
18
- })
18
+ }
19
19
  end
20
20
 
21
21
  it 'should use proc object to set optional value' do
@@ -23,10 +23,10 @@ describe Lastfm::Util do
23
23
  ['foo', nil],
24
24
  [:foo],
25
25
  [[:bar, Proc.new { 'xxx' }]
26
- ]).should eql({
26
+ ]).should == {
27
27
  :foo => 'foo',
28
28
  :bar => 'xxx',
29
- })
29
+ }
30
30
  end
31
31
  end
32
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lastfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-26 00:00:00.000000000 Z
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70299718961480 !ruby/object:Gem::Requirement
16
+ requirement: &70152548903840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70299718961480
24
+ version_requirements: *70152548903840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: xml-simple
27
- requirement: &70299718960660 !ruby/object:Gem::Requirement
27
+ requirement: &70152548903220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70299718960660
35
+ version_requirements: *70152548903220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &70299718959900 !ruby/object:Gem::Requirement
38
+ requirement: &70152549401280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.0.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70299718959900
46
+ version_requirements: *70152549401280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70299718975280 !ruby/object:Gem::Requirement
49
+ requirement: &70152549400600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.8.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70299718975280
57
+ version_requirements: *70152549400600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70299718974480 !ruby/object:Gem::Requirement
60
+ requirement: &70152549399960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70299718974480
68
+ version_requirements: *70152549399960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &70299718973600 !ruby/object:Gem::Requirement
71
+ requirement: &70152549399280 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70299718973600
79
+ version_requirements: *70152549399280
80
80
  description: A ruby interface for Last.fm web services version 2.0
81
81
  email: youpy@buycheapviagraonlinenow.com
82
82
  executables: []
@@ -99,8 +99,10 @@ files:
99
99
  - lib/lastfm/method_category/artist.rb
100
100
  - lib/lastfm/method_category/auth.rb
101
101
  - lib/lastfm/method_category/base.rb
102
+ - lib/lastfm/method_category/event.rb
102
103
  - lib/lastfm/method_category/geo.rb
103
104
  - lib/lastfm/method_category/library.rb
105
+ - lib/lastfm/method_category/tag.rb
104
106
  - lib/lastfm/method_category/track.rb
105
107
  - lib/lastfm/method_category/user.rb
106
108
  - lib/lastfm/response.rb
@@ -108,11 +110,15 @@ files:
108
110
  - spec/fixtures/album_get_info.xml
109
111
  - spec/fixtures/artist_get_events.xml
110
112
  - spec/fixtures/artist_get_info.xml
113
+ - spec/fixtures/artist_get_similar.xml
114
+ - spec/fixtures/artist_get_tags.xml
115
+ - spec/fixtures/event_get_info.xml
111
116
  - spec/fixtures/geo_get_events.xml
112
117
  - spec/fixtures/library_get_artists.xml
113
118
  - spec/fixtures/library_get_tracks.xml
114
119
  - spec/fixtures/ng.xml
115
120
  - spec/fixtures/ok.xml
121
+ - spec/fixtures/tag_get_top_artists.xml
116
122
  - spec/fixtures/track_get_correction.xml
117
123
  - spec/fixtures/track_get_info.xml
118
124
  - spec/fixtures/track_get_info_force_array.xml
@@ -125,12 +131,25 @@ files:
125
131
  - spec/fixtures/user_get_info.xml
126
132
  - spec/fixtures/user_get_loved_tracks.xml
127
133
  - spec/fixtures/user_get_neighbours.xml
134
+ - spec/fixtures/user_get_personal_tags.xml
135
+ - spec/fixtures/user_get_personal_tags_albums.xml
136
+ - spec/fixtures/user_get_personal_tags_artists.xml
137
+ - spec/fixtures/user_get_personal_tags_tracks.xml
128
138
  - spec/fixtures/user_get_recent_tracks.xml
129
139
  - spec/fixtures/user_get_top_albums.xml
130
140
  - spec/fixtures/user_get_top_artists.xml
141
+ - spec/fixtures/user_get_top_tags.xml
131
142
  - spec/fixtures/user_get_top_tracks.xml
132
143
  - spec/lastfm_spec.rb
133
144
  - spec/method_category_spec.rb
145
+ - spec/method_specs/album_spec.rb
146
+ - spec/method_specs/artist_spec.rb
147
+ - spec/method_specs/event_spec.rb
148
+ - spec/method_specs/geo_spec.rb
149
+ - spec/method_specs/library_spec.rb
150
+ - spec/method_specs/tag_spec.rb
151
+ - spec/method_specs/track_spec.rb
152
+ - spec/method_specs/user_spec.rb
134
153
  - spec/response_spec.rb
135
154
  - spec/spec_helper.rb
136
155
  - spec/util_spec.rb
@@ -148,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
167
  version: '0'
149
168
  segments:
150
169
  - 0
151
- hash: 791443162221732736
170
+ hash: 877929140514225915
152
171
  required_rubygems_version: !ruby/object:Gem::Requirement
153
172
  none: false
154
173
  requirements: