lastfm 1.26.0 → 1.27.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -2
  3. data/.travis.yml +3 -0
  4. data/README.md +14 -5
  5. data/lastfm.gemspec +3 -4
  6. data/lib/lastfm.rb +0 -1
  7. data/lib/lastfm/method_category/album.rb +68 -1
  8. data/lib/lastfm/method_category/artist.rb +7 -0
  9. data/lib/lastfm/method_category/base.rb +1 -1
  10. data/lib/lastfm/method_category/track.rb +5 -2
  11. data/lib/lastfm/method_category/user.rb +2 -2
  12. data/lib/lastfm/response.rb +19 -1
  13. data/lib/lastfm/util.rb +6 -11
  14. data/spec/fixtures/album_get_buylinks.xml +31 -0
  15. data/spec/fixtures/album_get_info_without_release_date.xml +184 -0
  16. data/spec/fixtures/album_get_shouts.xml +15 -0
  17. data/spec/fixtures/album_get_tags.xml +13 -0
  18. data/spec/fixtures/album_get_top_tags.xml +15 -0
  19. data/spec/fixtures/album_search.xml +35 -0
  20. data/spec/fixtures/album_search_no_match.xml +10 -0
  21. data/spec/fixtures/album_search_single_album.xml +23 -0
  22. data/spec/fixtures/artist_get_correction.xml +12 -0
  23. data/spec/fixtures/artist_search.xml +1 -1
  24. data/spec/fixtures/tag_search.xml +1 -1
  25. data/spec/fixtures/track_search_no_match.xml +11 -0
  26. data/spec/fixtures/track_search_single_track.xml +1 -1
  27. data/spec/fixtures/user_get_loved_tracks_no_tracks.xml +5 -0
  28. data/spec/fixtures/user_get_loved_tracks_single_track.xml +17 -0
  29. data/spec/lastfm_spec.rb +34 -34
  30. data/spec/method_category_spec.rb +1 -1
  31. data/spec/method_specs/album_spec.rb +255 -25
  32. data/spec/method_specs/artist_spec.rb +82 -70
  33. data/spec/method_specs/chart_spec.rb +13 -13
  34. data/spec/method_specs/event_spec.rb +3 -3
  35. data/spec/method_specs/geo_spec.rb +13 -13
  36. data/spec/method_specs/group_spec.rb +4 -4
  37. data/spec/method_specs/library_spec.rb +7 -7
  38. data/spec/method_specs/radio_spec.rb +10 -10
  39. data/spec/method_specs/tag_spec.rb +28 -28
  40. data/spec/method_specs/tasteometer_spec.rb +4 -4
  41. data/spec/method_specs/track_spec.rb +91 -73
  42. data/spec/method_specs/user_spec.rb +124 -94
  43. data/spec/response_spec.rb +6 -6
  44. data/spec/util_spec.rb +16 -16
  45. metadata +33 -23
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <shouts artist="Cher" album="Believe" page="1" perPage="50" totalPages="2" total="53">
4
+ <shout>
5
+ <body>A perfect Pop/Dance Masterpiece</body>
6
+ <author>top20fanatico</author>
7
+ <date>Wed, 7 Jan 2015 12:45:35</date>
8
+ </shout>
9
+ <shout>
10
+ <body>http://www.lastfm.com.br/music/Cher/+images/101972561</body>
11
+ <author>gabcmonteiro</author>
12
+ <date>Sun, 9 Nov 2014 12:07:06</date>
13
+ </shout>
14
+ </shouts>
15
+ </lfm>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <tags artist="Cher" album="Believe">
4
+ <tag>
5
+ <name>sourabh</name>
6
+ <url>http://www.last.fm/tag/sourabh</url>
7
+ </tag>
8
+ <tag>
9
+ <name>90s</name>
10
+ <url>http://www.last.fm/tag/90s</url>
11
+ </tag>
12
+ </tags>
13
+ </lfm>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <toptags artist="Radiohead" album="The Bends">
4
+ <tag>
5
+ <name>albums I own</name>
6
+ <count>100</count>
7
+ <url>http://www.last.fm/tag/albums%20i%20own</url>
8
+ </tag>
9
+ <tag>
10
+ <name>alternative rock</name>
11
+ <count>56</count>
12
+ <url>http://www.last.fm/tag/alternative%20rock</url>
13
+ </tag>
14
+ </toptags>
15
+ </lfm>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <results for="Believe">
4
+ <opensearch:Query role="request" searchTerms="Believe" startPage="1" />
5
+ <opensearch:totalResults>3926</opensearch:totalResults>
6
+ <opensearch:startIndex>0</opensearch:startIndex>
7
+ <opensearch:itemsPerPage>50</opensearch:itemsPerPage>
8
+ <albummatches>
9
+ <album>
10
+ <name>Believe</name>
11
+ <artist>Disturbed</artist>
12
+ <id>1418894</id>
13
+ <url>http://www.last.fm/music/Disturbed/Believe</url>
14
+ <image size="small">http://userserve-ak.last.fm/serve/34s/53553281.png</image>
15
+ <image size="medium">http://userserve-ak.last.fm/serve/64s/53553281.png</image>
16
+ <image size="large">http://userserve-ak.last.fm/serve/126/53553281.png</image>
17
+ <image size="extralarge">http://userserve-ak.last.fm/serve/300x300/53553281.png</image>
18
+ <streamable>0</streamable>
19
+ <mbid>ed32813a-cd20-4bb3-b3fd-bca6161deb17</mbid>
20
+ </album>
21
+ <album>
22
+ <name>Make Believe</name>
23
+ <artist>Weezer</artist>
24
+ <id>2025180</id>
25
+ <url>http://www.last.fm/music/Weezer/Make+Believe</url>
26
+ <image size="small">http://userserve-ak.last.fm/serve/34s/53692665.png</image>
27
+ <image size="medium">http://userserve-ak.last.fm/serve/64s/53692665.png</image>
28
+ <image size="large">http://userserve-ak.last.fm/serve/126/53692665.png</image>
29
+ <image size="extralarge">http://userserve-ak.last.fm/serve/300x300/53692665.png</image>
30
+ <streamable>0</streamable>
31
+ <mbid>9e7103bb-fc9a-4e5a-a90c-2a3ab4c08e19</mbid>
32
+ </album>
33
+ </albummatches>
34
+ </results>
35
+ </lfm>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <results for="Believe">
4
+ <opensearch:Query role="request" searchTerms="Believe" startPage="1" />
5
+ <opensearch:totalResults>0</opensearch:totalResults>
6
+ <opensearch:startIndex>0</opensearch:startIndex>
7
+ <opensearch:itemsPerPage>50</opensearch:itemsPerPage>
8
+ <albummatches></albummatches>
9
+ </results>
10
+ </lfm>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <results for="Believe">
4
+ <opensearch:Query role="request" searchTerms="Believe" startPage="1" />
5
+ <opensearch:totalResults>3926</opensearch:totalResults>
6
+ <opensearch:startIndex>0</opensearch:startIndex>
7
+ <opensearch:itemsPerPage>50</opensearch:itemsPerPage>
8
+ <albummatches>
9
+ <album>
10
+ <name>Believe</name>
11
+ <artist>Disturbed</artist>
12
+ <id>1418894</id>
13
+ <url>http://www.last.fm/music/Disturbed/Believe</url>
14
+ <image size="small">http://userserve-ak.last.fm/serve/34s/53553281.png</image>
15
+ <image size="medium">http://userserve-ak.last.fm/serve/64s/53553281.png</image>
16
+ <image size="large">http://userserve-ak.last.fm/serve/126/53553281.png</image>
17
+ <image size="extralarge">http://userserve-ak.last.fm/serve/300x300/53553281.png</image>
18
+ <streamable>0</streamable>
19
+ <mbid>ed32813a-cd20-4bb3-b3fd-bca6161deb17</mbid>
20
+ </album>
21
+ </albummatches>
22
+ </results>
23
+ </lfm>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <corrections>
4
+ <correction index="0">
5
+ <artist>
6
+ <name>Guns N' Roses</name>
7
+ <mbid>eeb1195b-f213-4ce1-b28c-8565211f8e43</mbid>
8
+ <url>http://www.last.fm/music/Guns+N%27+Roses</url>
9
+ </artist>
10
+ </correction>
11
+ </corrections>
12
+ </lfm>
@@ -1,5 +1,5 @@
1
1
  <lfm status="ok">
2
- <results xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" for="RADWIMPS">
2
+ <results for="RADWIMPS">
3
3
  <opensearch:Query role="request" searchTerms="RADWIMPS" startPage="1"/>
4
4
  <opensearch:totalResults>3</opensearch:totalResults>
5
5
  <opensearch:startIndex>0</opensearch:startIndex>
@@ -1,7 +1,7 @@
1
1
 
2
2
  <?xml version="1.0" encoding="utf-8"?>
3
3
  <lfm status="ok">
4
- <results for="disco" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
4
+ <results for="disco">
5
5
  <opensearch:Query role="request" searchTerms="disco" startPage="1" />
6
6
  <opensearch:totalResults>1172</opensearch:totalResults>
7
7
  <opensearch:startIndex>0</opensearch:startIndex>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <results for="Believe">
4
+ <opensearch:Query role="request" searchTerms="Believe" startPage="1"/>
5
+ <opensearch:totalResults>0</opensearch:totalResults>
6
+ <opensearch:startIndex>0</opensearch:startIndex>
7
+ <opensearch:itemsPerPage>10</opensearch:itemsPerPage>
8
+ <trackmatches>
9
+ </trackmatches>
10
+ </results>
11
+ </lfm>
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <lfm status="ok">
3
- <results xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" for="Believe">
3
+ <results for="Believe">
4
4
  <opensearch:Query role="request" searchTerms="Believe" startPage="3"/>
5
5
  <opensearch:totalResults>40540</opensearch:totalResults>
6
6
  <opensearch:startIndex>20</opensearch:startIndex>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <lovedtracks user="skr" page="0" perPage="50" totalPages="0" total="0">
4
+ </lovedtracks>
5
+ </lfm>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <lfm status="ok">
3
+ <lovedtracks user="skr" page="1" perPage="50" totalPages="4" total="180">
4
+ <track>
5
+ <name>I Spy</name>
6
+ <mbid/>
7
+ <url>http://www.last.fm/music/Mikhael+Paskalev/_/I+Spy</url>
8
+ <date uts="1329859504">21 Feb 2012, 21:25</date>
9
+ <artist>
10
+ <name>Mikhael Paskalev</name>
11
+ <mbid/>
12
+ <url>http://www.last.fm/music/Mikhael+Paskalev</url>
13
+ </artist>
14
+ <streamable fulltrack="0">0</streamable>
15
+ </track>
16
+ </lovedtracks>
17
+ </lfm>
@@ -5,105 +5,105 @@ describe "Lastfm" do
5
5
 
6
6
  describe '.new' do
7
7
  it 'should instantiate' do
8
- @lastfm.should be_an_instance_of(Lastfm)
8
+ expect(@lastfm).to be_an_instance_of(Lastfm)
9
9
  end
10
10
  end
11
11
 
12
12
  describe '#request' do
13
13
  it 'should post' do
14
- mock_response = mock(HTTParty::Response)
15
- HTTPRequest.should_receive(:post).with('/', :body => {
14
+ mock_response = double(HTTParty::Response)
15
+ expect(HTTPRequest).to receive(:post).with('/', :body => {
16
16
  :foo => 'bar',
17
17
  :method => 'xxx.yyy',
18
18
  :api_key => 'xxx',
19
19
  }).and_return(mock_response)
20
- mock_response.should_receive(:body).and_return(@response_xml)
20
+ expect(mock_response).to receive(:body).and_return(@response_xml)
21
21
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post, false, false)
22
22
  end
23
23
 
24
24
  it 'should post with signature' do
25
- mock_response = mock(HTTParty::Response)
26
- HTTPRequest.should_receive(:post).with('/', :body => {
25
+ mock_response = double(HTTParty::Response)
26
+ expect(HTTPRequest).to receive(:post).with('/', :body => {
27
27
  :foo => 'bar',
28
28
  :method => 'xxx.yyy',
29
29
  :api_key => 'xxx',
30
30
  :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyyyy'),
31
31
  }).and_return(mock_response)
32
- mock_response.should_receive(:body).and_return(@response_xml)
32
+ expect(mock_response).to receive(:body).and_return(@response_xml)
33
33
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post, true, false)
34
34
  end
35
35
 
36
36
  it 'should post with signature and session (request with authentication)' do
37
- mock_response = mock(HTTParty::Response)
37
+ mock_response = double(HTTParty::Response)
38
38
  @lastfm.session = 'abcdef'
39
- HTTPRequest.should_receive(:post).with('/', :body => {
39
+ expect(HTTPRequest).to receive(:post).with('/', :body => {
40
40
  :foo => 'bar',
41
41
  :method => 'xxx.yyy',
42
42
  :api_key => 'xxx',
43
43
  :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyskabcdefyyy'),
44
44
  :sk => 'abcdef',
45
45
  }).and_return(mock_response)
46
- mock_response.should_receive(:body).and_return(@response_xml)
46
+ expect(mock_response).to receive(:body).and_return(@response_xml)
47
47
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post, true, true)
48
48
  end
49
49
 
50
50
  it 'should get' do
51
- mock_response = mock(HTTParty::Response)
52
- HTTPRequest.should_receive(:get).with('/', :query => {
51
+ mock_response = double(HTTParty::Response)
52
+ expect(HTTPRequest).to receive(:get).with('/', :query => {
53
53
  :foo => 'bar',
54
54
  :method => 'xxx.yyy',
55
55
  :api_key => 'xxx',
56
56
  }).and_return(mock_response)
57
- mock_response.should_receive(:body).and_return(@response_xml)
57
+ expect(mock_response).to receive(:body).and_return(@response_xml)
58
58
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :get, false, false)
59
59
  end
60
60
 
61
61
  it 'should get with signature (request for authentication)' do
62
- mock_response = mock(HTTParty::Response)
63
- HTTPRequest.should_receive(:get).with('/', :query => {
62
+ mock_response = double(HTTParty::Response)
63
+ expect(HTTPRequest).to receive(:get).with('/', :query => {
64
64
  :foo => 'bar',
65
65
  :method => 'xxx.yyy',
66
66
  :api_key => 'xxx',
67
67
  :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyyyy'),
68
68
  }).and_return(mock_response)
69
- mock_response.should_receive(:body).and_return(@response_xml)
69
+ expect(mock_response).to receive(:body).and_return(@response_xml)
70
70
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :get, true, false)
71
71
  end
72
72
 
73
73
  it 'should get with signature and session' do
74
- mock_response = mock(HTTParty::Response)
74
+ mock_response = double(HTTParty::Response)
75
75
  @lastfm.session = 'abcdef'
76
- HTTPRequest.should_receive(:get).with('/', :query => {
76
+ expect(HTTPRequest).to receive(:get).with('/', :query => {
77
77
  :foo => 'bar',
78
78
  :method => 'xxx.yyy',
79
79
  :api_key => 'xxx',
80
80
  :api_sig => Digest::MD5.hexdigest('api_keyxxxfoobarmethodxxx.yyyskabcdefyyy'),
81
81
  :sk => 'abcdef',
82
82
  }).and_return(mock_response)
83
- mock_response.should_receive(:body).and_return(@response_xml)
83
+ expect(mock_response).to receive(:body).and_return(@response_xml)
84
84
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :get, true, true)
85
85
  end
86
86
 
87
87
  it 'should raise an error if an api error is ocuured' do
88
- mock_response = mock(HTTParty::Response)
89
- mock_response.should_receive(:body).and_return(open(fixture('ng.xml')).read)
90
- HTTPRequest.should_receive(:post).and_return(mock_response)
88
+ mock_response = double(HTTParty::Response)
89
+ expect(mock_response).to receive(:body).and_return(open(fixture('ng.xml')).read)
90
+ expect(HTTPRequest).to receive(:post).and_return(mock_response)
91
91
 
92
- lambda {
92
+ expect {
93
93
  @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post)
94
- }.should raise_error(Lastfm::ApiError, 'Invalid API key - You must be granted a valid key by last.fm') {|error|
95
- error.code.should == 10
94
+ }.to raise_error(Lastfm::ApiError, 'Invalid API key - You must be granted a valid key by last.fm') {|error|
95
+ expect(error.code).to eq(10)
96
96
  }
97
97
  end
98
98
  end
99
99
 
100
100
  describe '#auth' do
101
101
  it 'should return an instance of Lastfm::Auth' do
102
- @lastfm.auth.should be_an_instance_of(Lastfm::MethodCategory::Auth)
102
+ expect(@lastfm.auth).to be_an_instance_of(Lastfm::MethodCategory::Auth)
103
103
  end
104
104
 
105
105
  it 'should get token' do
106
- @lastfm.should_receive(:request).
106
+ expect(@lastfm).to receive(:request).
107
107
  with('auth.getToken', {}, :get, true).
108
108
  and_return(make_response(<<XML))
109
109
  <?xml version="1.0" encoding="utf-8"?>
@@ -111,11 +111,11 @@ describe "Lastfm" do
111
111
  <token>xxxyyyzzz</token></lfm>
112
112
  XML
113
113
 
114
- @lastfm.auth.get_token.should == 'xxxyyyzzz'
114
+ expect(@lastfm.auth.get_token).to eq('xxxyyyzzz')
115
115
  end
116
116
 
117
117
  it 'should get session' do
118
- @lastfm.should_receive(:request).
118
+ expect(@lastfm).to receive(:request).
119
119
  with('auth.getSession', { :token => 'xxxyyyzzz' }, :get, true).
120
120
  and_return(make_response(<<XML))
121
121
  <?xml version="1.0" encoding="utf-8"?>
@@ -128,12 +128,12 @@ XML
128
128
  </lfm>
129
129
  XML
130
130
  session = @lastfm.auth.get_session('xxxyyyzzz')
131
- session['name'].should == 'MyLastFMUsername'
132
- session['key'].should == 'zzzyyyxxx'
131
+ expect(session['name']).to eq('MyLastFMUsername')
132
+ expect(session['key']).to eq('zzzyyyxxx')
133
133
  end
134
134
 
135
135
  it 'should get mobile session' do
136
- @lastfm.should_receive(:request).
136
+ expect(@lastfm).to receive(:request).
137
137
  with('auth.getMobileSession', { :username => 'xxxyyyzzz', :password => 'sekretz' }, :post, true, false, true).
138
138
  and_return(make_response(<<XML))
139
139
  <?xml version="1.0" encoding="utf-8"?>
@@ -146,8 +146,8 @@ XML
146
146
  </lfm>
147
147
  XML
148
148
  session = @lastfm.auth.get_mobile_session('xxxyyyzzz', 'sekretz')
149
- session['name'].should == 'MyLastFMUsername'
150
- session['key'].should == 'zzzyyyxxx'
149
+ expect(session['name']).to eq('MyLastFMUsername')
150
+ expect(session['key']).to eq('zzzyyyxxx')
151
151
  end
152
152
  end
153
153
  end
@@ -6,6 +6,6 @@ describe 'Lastfm::MethodCategory' do
6
6
  end
7
7
 
8
8
  it 'should have instance of Lastfm' do
9
- Lastfm::MethodCategory::Base.new(@lastfm).instance_eval { @lastfm }.should equal(@lastfm)
9
+ expect(Lastfm::MethodCategory::Base.new(@lastfm).instance_eval { @lastfm }).to equal(@lastfm)
10
10
  end
11
11
  end
@@ -1,49 +1,279 @@
1
+ # encoding: utf-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
3
 
3
4
  describe '#album' do
4
5
  before { init_lastfm }
5
6
 
6
7
  it 'should return an instance of Lastfm::Album' do
7
- @lastfm.album.should be_an_instance_of(Lastfm::MethodCategory::Album)
8
+ expect(@lastfm.album).to be_an_instance_of(Lastfm::MethodCategory::Album)
9
+ end
10
+
11
+ describe '#add_tags' do
12
+ it 'should add tags' do
13
+ expect(@lastfm).to receive(:request).with('album.addTags', {
14
+ :artist => 'foo artist',
15
+ :album => 'foo track',
16
+ :tags => 'aaa,bbb,ccc'
17
+ }, :post, true, true).and_return(@ok_response)
18
+
19
+ expect(@lastfm.album.add_tags(
20
+ :artist => 'foo artist',
21
+ :album => 'foo track',
22
+ :tags => 'aaa,bbb,ccc'
23
+ )).to be_truthy
24
+ end
25
+ end
26
+
27
+ describe '#get_buylinks' do
28
+ it 'should get buylinks' do
29
+ expect(@lastfm).to receive(:request).with('album.getBuylinks', {
30
+ :artist => 'radiohead',
31
+ :album => 'in rainbows',
32
+ :country => 'united kingdom',
33
+ :autocorrect => nil
34
+ }).and_return(make_response('album_get_buylinks'))
35
+
36
+ buylinks = @lastfm.album.get_buylinks(
37
+ :artist => 'radiohead',
38
+ :album => 'in rainbows',
39
+ :country => 'united kingdom'
40
+ )
41
+
42
+ expect(buylinks['physicals'].size).to eq(1)
43
+ expect(buylinks['physicals']['affiliation']['supplierName']).to eq('Amazon')
44
+ expect(buylinks['physicals']['affiliation']['price']['currency']).to eq('GBP')
45
+ expect(buylinks['physicals']['affiliation']['price']['amount']).to eq('6.34')
46
+ expect(buylinks['physicals']['affiliation']['price']['formatted']).to eq('£6.34')
47
+ expect(buylinks['physicals']['affiliation']['buyLink']).to eq('http://www.last.fm/affiliate/byid/8/3418994/1/ws.album.buylinks.f4e2585261d8d10d3297e181d68940fc')
48
+
49
+ expect(buylinks['downloads'].size).to eq(1)
50
+ expect(buylinks['downloads']['affiliation']['supplierName']).to eq('Amazon MP3')
51
+ expect(buylinks['downloads']['affiliation']['price']['currency']).to eq('GBP')
52
+ expect(buylinks['downloads']['affiliation']['price']['amount']).to eq('7.99')
53
+ expect(buylinks['downloads']['affiliation']['price']['formatted']).to eq('£7.99')
54
+ expect(buylinks['downloads']['affiliation']['buyLink']).to eq('http://www.last.fm/affiliate/byid/8/3418994/44/ws.album.buylinks.f4e2585261d8d10d3297e181d68940fc')
55
+ end
56
+
57
+ it 'should get buylinks by mbid' do
58
+ expect(@lastfm).to receive(:request).with('album.getBuylinks', {
59
+ :mbid => 'radiohead',
60
+ :country => 'united kingdom',
61
+ :autocorrect => nil
62
+ }).and_return(make_response('album_get_buylinks'))
63
+
64
+ buylinks = @lastfm.album.get_buylinks(
65
+ :mbid => 'radiohead',
66
+ :country => 'united kingdom'
67
+ )
68
+
69
+ expect(buylinks['physicals'].size).to eq(1)
70
+ expect(buylinks['physicals']['affiliation']['supplierName']).to eq('Amazon')
71
+ expect(buylinks['physicals']['affiliation']['price']['currency']).to eq('GBP')
72
+ expect(buylinks['physicals']['affiliation']['price']['amount']).to eq('6.34')
73
+ expect(buylinks['physicals']['affiliation']['price']['formatted']).to eq('£6.34')
74
+ expect(buylinks['physicals']['affiliation']['buyLink']).to eq('http://www.last.fm/affiliate/byid/8/3418994/1/ws.album.buylinks.f4e2585261d8d10d3297e181d68940fc')
75
+
76
+ expect(buylinks['downloads'].size).to eq(1)
77
+ expect(buylinks['downloads']['affiliation']['supplierName']).to eq('Amazon MP3')
78
+ expect(buylinks['downloads']['affiliation']['price']['currency']).to eq('GBP')
79
+ expect(buylinks['downloads']['affiliation']['price']['amount']).to eq('7.99')
80
+ expect(buylinks['downloads']['affiliation']['price']['formatted']).to eq('£7.99')
81
+ expect(buylinks['downloads']['affiliation']['buyLink']).to eq('http://www.last.fm/affiliate/byid/8/3418994/44/ws.album.buylinks.f4e2585261d8d10d3297e181d68940fc')
82
+ end
83
+
84
+ it 'should raise ArgumentError without country' do
85
+ expect {@lastfm.album.get_buylinks(
86
+ :artist => 'radiohead',
87
+ :album => 'in rainbows'
88
+ )}.to raise_error(ArgumentError)
89
+
90
+ expect {@lastfm.album.get_buylinks(
91
+ :mbid => 'radiohead',
92
+ )}.to raise_error(ArgumentError)
93
+ end
8
94
  end
9
95
 
10
96
  describe '#get_info' do
11
97
  it 'should get info by artist and album' do
12
- @lastfm.should_receive(:request).with('album.getInfo', {
98
+ expect(@lastfm).to receive(:request).with('album.getInfo', {
13
99
  :artist => 'Cher', :album => 'Believe'
14
100
  }).and_return(make_response('album_get_info'))
15
101
 
16
102
  album = @lastfm.album.get_info(:artist => 'Cher', :album => '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'
103
+ expect(album['name']).to eq('Believe')
104
+ expect(album['artist']).to eq('Cher')
105
+ expect(album['id']).to eq('2026126')
106
+ expect(album['mbid']).to eq('61bf0388-b8a9-48f4-81d1-7eb02706dfb0')
107
+ expect(album['url']).to eq('http://www.last.fm/music/Cher/Believe')
108
+ expect(album['image'].size).to eq(5)
109
+ expect(album['releasedate']).to eq('6 Apr 1999, 00:00')
110
+ expect(album['tracks']['track'].size).to eq(10)
111
+ expect(album['tracks']['track'][0]['name']).to eq('Believe')
112
+ expect(album['tracks']['track'][0]['duration']).to eq('239')
113
+ expect(album['tracks']['track'][0]['url']).to eq('http://www.last.fm/music/Cher/_/Believe')
28
114
  end
29
115
 
30
116
  it 'should get info by mbid' do
31
- @lastfm.should_receive(:request).with('album.getInfo', {
117
+ expect(@lastfm).to receive(:request).with('album.getInfo', {
32
118
  :mbid => 'xxxxx'
33
119
  }).and_return(make_response('album_get_info'))
34
120
 
35
121
  album = @lastfm.album.get_info(:mbid => 'xxxxx')
36
- album['name'].should == 'Believe'
37
- album['artist'].should == 'Cher'
38
- album['id'].should == '2026126'
39
- album['mbid'].should == '61bf0388-b8a9-48f4-81d1-7eb02706dfb0'
40
- album['url'].should == 'http://www.last.fm/music/Cher/Believe'
41
- album['image'].size.should == 5
42
- album['releasedate'].should == '6 Apr 1999, 00:00'
43
- album['tracks']['track'].size.should == 10
44
- album['tracks']['track'][0]['name'].should == 'Believe'
45
- album['tracks']['track'][0]['duration'].should == '239'
46
- album['tracks']['track'][0]['url'].should == 'http://www.last.fm/music/Cher/_/Believe'
122
+ expect(album['name']).to eq('Believe')
123
+ expect(album['artist']).to eq('Cher')
124
+ expect(album['id']).to eq('2026126')
125
+ expect(album['mbid']).to eq('61bf0388-b8a9-48f4-81d1-7eb02706dfb0')
126
+ expect(album['url']).to eq('http://www.last.fm/music/Cher/Believe')
127
+ expect(album['image'].size).to eq(5)
128
+ expect(album['releasedate']).to eq('6 Apr 1999, 00:00')
129
+ expect(album['tracks']['track'].size).to eq(10)
130
+ expect(album['tracks']['track'][0]['name']).to eq('Believe')
131
+ expect(album['tracks']['track'][0]['duration']).to eq('239')
132
+ expect(album['tracks']['track'][0]['url']).to eq('http://www.last.fm/music/Cher/_/Believe')
133
+ end
134
+
135
+ it 'works without release date' do
136
+ expect(@lastfm).to receive(:request).with('album.getInfo', {
137
+ :mbid => 'xxxxx'
138
+ }).and_return(make_response('album_get_info_without_release_date'))
139
+
140
+ album = @lastfm.album.get_info(:mbid => 'xxxxx')
141
+ expect(album['name']).to eq('Believe')
142
+ end
143
+ end
144
+
145
+ describe '#get_shouts' do
146
+ it 'should get shouts' do
147
+ expect(@lastfm).to receive(:request).with('album.getShouts', {
148
+ :artist => 'Cher',
149
+ :album => 'Believe',
150
+ :autocorrect => nil,
151
+ :limit => nil,
152
+ :page => nil
153
+ }).and_return(make_response('album_get_shouts'))
154
+
155
+ shouts = @lastfm.album.get_shouts(
156
+ :artist => 'Cher',
157
+ :album => 'Believe')
158
+ expect(shouts.size).to eq(2)
159
+ expect(shouts[0]['body']).to eq('A perfect Pop/Dance Masterpiece')
160
+ expect(shouts[0]['author']).to eq('top20fanatico')
161
+ expect(shouts[0]['date']).to eq('Wed, 7 Jan 2015 12:45:35')
162
+ end
163
+ end
164
+
165
+ describe '#get_tags' do
166
+ it 'should get tags' do
167
+ expect(@lastfm).to receive(:request).with('album.getTags', {
168
+ :artist => 'Cher',
169
+ :album => 'Believe',
170
+ :autocorrect => nil
171
+ }, :get, true, true).and_return(make_response('album_get_tags'))
172
+
173
+ tags = @lastfm.album.get_tags(
174
+ :artist => 'Cher',
175
+ :album => 'Believe')
176
+ expect(tags.size).to eq(2)
177
+ expect(tags[0]['name']).to eq('sourabh')
178
+ expect(tags[0]['url']).to eq('http://www.last.fm/tag/sourabh')
179
+ end
180
+ end
181
+
182
+ describe '#get_top_tags' do
183
+ it 'should get top tags' do
184
+ expect(@lastfm).to receive(:request).with('album.getTopTags', {
185
+ :artist => 'Radiohead',
186
+ :album => 'The Bends',
187
+ :autocorrect => nil
188
+ }).and_return(make_response('album_get_top_tags'))
189
+
190
+ tags = @lastfm.album.get_top_tags(
191
+ :artist => 'Radiohead',
192
+ :album => 'The Bends')
193
+ expect(tags.size).to eq(2)
194
+ expect(tags[0]['name']).to eq('albums I own')
195
+ expect(tags[0]['count']).to eq('100')
196
+ expect(tags[0]['url']).to eq('http://www.last.fm/tag/albums%20i%20own')
197
+ end
198
+ end
199
+
200
+ describe '#remove_tag' do
201
+ it 'should remove tag' do
202
+ expect(@lastfm).to receive(:request).with('album.removeTag', {
203
+ :artist => 'foo artist',
204
+ :album => 'foo track',
205
+ :tag => 'aaa'
206
+ }, :post, true, true).and_return(@ok_response)
207
+
208
+ expect(@lastfm.album.remove_tag(
209
+ :artist => 'foo artist',
210
+ :album => 'foo track',
211
+ :tag => 'aaa')).to be_truthy
212
+ end
213
+ end
214
+
215
+ describe '#search' do
216
+ it 'should search' do
217
+ expect(@lastfm).to receive(:request).with('album.search', {
218
+ :album => 'Believe',
219
+ :limit => nil,
220
+ :page => nil,
221
+ }).and_return(make_response('album_search'))
222
+
223
+ albums = @lastfm.album.search(:album => 'Believe')
224
+
225
+ expect(albums['results']['for']).to eq('Believe')
226
+ expect(albums['results']['totalResults']).to eq('3926')
227
+ expect(albums['results']['albummatches']['album'].size).to eq(2)
228
+ expect(albums['results']['albummatches']['album'][0]['name']).to eq('Believe')
229
+ end
230
+
231
+ it 'should always return an array of albums' do
232
+ expect(@lastfm).to receive(:request).with('album.search', {
233
+ :album => 'Believe',
234
+ :limit => nil,
235
+ :page => nil,
236
+ }).and_return(make_response('album_search_single_album'))
237
+
238
+ albums = @lastfm.album.search(:album => 'Believe')
239
+
240
+ expect(albums['results']['for']).to eq('Believe')
241
+ expect(albums['results']['totalResults']).to eq('3926')
242
+ expect(albums['results']['albummatches']['album'].size).to eq(1)
243
+ expect(albums['results']['albummatches']['album'][0]['name']).to eq('Believe')
244
+ end
245
+
246
+ it 'should return an empty array if no match found' do
247
+ expect(@lastfm).to receive(:request).with('album.search', {
248
+ :album => 'Believe',
249
+ :limit => nil,
250
+ :page => nil,
251
+ }).and_return(make_response('album_search_no_match'))
252
+
253
+ albums = @lastfm.album.search(:album => 'Believe')
254
+
255
+ expect(albums['results']['for']).to eq('Believe')
256
+ expect(albums['results']['totalResults']).to eq('0')
257
+ expect(albums['results']['albummatches']['album'].size).to eq(0)
258
+ end
259
+ end
260
+
261
+ describe '#share' do
262
+ it 'should share' do
263
+ expect(@lastfm).to receive(:request).with('album.share', {
264
+ :artist => 'bar artist',
265
+ :album => 'bar album',
266
+ :recipient => 'bar@example.com',
267
+ :message => 'this is a message',
268
+ :public => nil,
269
+ }, :post, true, true).and_return(@ok_response)
270
+
271
+ expect(@lastfm.album.share(
272
+ :artist => 'bar artist',
273
+ :album => 'bar album',
274
+ :recipient => 'bar@example.com',
275
+ :message => 'this is a message',
276
+ )).to be_truthy
47
277
  end
48
278
  end
49
279
  end