echonest-ruby-api 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://developer.echonest.com/api/v4/artist/video?api_key=BNOAEBT3IZYZI6WXI&format=json&name=Weezer&results=10
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Tue, 25 Mar 2014 17:51:04 GMT
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '3006'
21
+ Vary:
22
+ - Accept-Encoding
23
+ X-Request-Id:
24
+ - MAyICk1ET5GlgjjVQx8UtQ
25
+ Etag:
26
+ - ! '"6e6c084e73cbd1b42076bf7dd1da50f49b40f49d"'
27
+ X-Worker-Node:
28
+ - 7cbef:11396
29
+ X-Ratelimit-Remaining:
30
+ - '19'
31
+ Server:
32
+ - TornadoServer/3.1
33
+ X-Ratelimit-Limit:
34
+ - '20'
35
+ X-Api-Key:
36
+ - BNOAEBT3IZYZI6WXI
37
+ Cache-Control:
38
+ - max-age=86400
39
+ Access-Control-Allow-Origin:
40
+ - ! '*'
41
+ X-Ratelimit-Used:
42
+ - '1'
43
+ Connection:
44
+ - Keep-alive
45
+ Keep-Alive:
46
+ - timeout=15, max=100
47
+ Via:
48
+ - 1.1 ID-0000627501223746 uproxy-3
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ! '{"response": {"status": {"version": "4.2", "code": 0, "message":
52
+ "Success"}, "start": 0, "total": 744, "video": [{"title": "Weezer - I Just
53
+ Threw Out The Love of My Dreams", "url": "http://www.youtube.com/watch?v=CFXOas-fCq8&feature=youtube_gdata_player",
54
+ "site": "youtube.com", "date_found": "2014-03-22T00:00:00", "image_url": "http://i.ytimg.com/vi/CFXOas-fCq8/default.jpg",
55
+ "id": "611289c4d72f6e507694c75f4552f9b2"}, {"title": "Weezer- Everyone", "url":
56
+ "http://www.youtube.com/watch?v=iZKC4pHw1zc&feature=youtube_gdata_player",
57
+ "site": "youtube.com", "date_found": "2014-03-08T00:00:00", "image_url": "http://i.ytimg.com/vi/iZKC4pHw1zc/default.jpg",
58
+ "id": "3f763e82869488809411e63f4cc031b6"}, {"title": "Weezer - Smile", "url":
59
+ "http://www.youtube.com/watch?v=YUeKEB41OCM&feature=youtube_gdata_player",
60
+ "site": "youtube.com", "date_found": "2014-03-08T00:00:00", "image_url": "http://i.ytimg.com/vi/YUeKEB41OCM/default.jpg",
61
+ "id": "cd47f4d58add3b4ddb2a00c1b7c851c9"}, {"title": "Weezer - Beverly Hills",
62
+ "url": "http://www.youtube.com/watch?v=U4vSDCdAwPE&feature=youtube_gdata_player",
63
+ "site": "youtube.com", "date_found": "2014-03-08T00:00:00", "image_url": "http://i.ytimg.com/vi/U4vSDCdAwPE/default.jpg",
64
+ "id": "bd22637570143ef73ebbb0817485e7c6"}, {"title": "Weezer - Hash Pipe",
65
+ "url": "http://www.youtube.com/watch?v=aDG_qive-uk&feature=youtube_gdata_player",
66
+ "site": "youtube.com", "date_found": "2014-03-08T00:00:00", "image_url": "http://i.ytimg.com/vi/aDG_qive-uk/default.jpg",
67
+ "id": "5614b2e3f6933379c2e862090404ae04"}, {"title": "Everybody Get Dangerous
68
+ - Weezer", "url": "http://www.youtube.com/watch?v=q15RYYK7wMI&feature=youtube_gdata_player",
69
+ "site": "youtube.com", "date_found": "2014-03-08T00:00:00", "image_url": "http://i.ytimg.com/vi/q15RYYK7wMI/default.jpg",
70
+ "id": "5f0dfa0255f408ccff9e83ed59569949"}, {"title": "Everybody Get Dangerous
71
+ - Weezer", "url": "http://www.youtube.com/watch?v=kBaoxmYha3k&feature=youtube_gdata_player",
72
+ "site": "youtube.com", "date_found": "2014-03-05T00:00:00", "image_url": "http://i.ytimg.com/vi/kBaoxmYha3k/default.jpg",
73
+ "id": "e177249d64da400ac9943d50de4995a8"}, {"title": "Weezer - Perfect Situation",
74
+ "url": "http://www.youtube.com/watch?v=TgcK8jDFadE&feature=youtube_gdata_player",
75
+ "site": "youtube.com", "date_found": "2014-03-05T00:00:00", "image_url": "http://i.ytimg.com/vi/TgcK8jDFadE/default.jpg",
76
+ "id": "f555e9de148787cf45c67a5f7334e0eb"}, {"title": "weezer- the greatest
77
+ man that ever lived (with lyrics)", "url": "http://www.youtube.com/watch?v=A60grS9QKg0&feature=youtube_gdata_player",
78
+ "site": "youtube.com", "date_found": "2014-03-05T00:00:00", "image_url": "http://i.ytimg.com/vi/A60grS9QKg0/default.jpg",
79
+ "id": "38aedba9bf15272dc5d167da6c8cb370"}, {"title": "Weezer - Simple Pages",
80
+ "url": "http://www.youtube.com/watch?v=m9EqvOqz4ko&feature=youtube_gdata_player",
81
+ "site": "youtube.com", "date_found": "2014-03-05T00:00:00", "image_url": "http://i.ytimg.com/vi/m9EqvOqz4ko/default.jpg",
82
+ "id": "488384dd01dc3d820a89d1f381727347"}]}}'
83
+ http_version:
84
+ recorded_at: Tue, 25 Mar 2014 17:50:37 GMT
85
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,91 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://developer.echonest.com/api/v4/artist/top_hottt?api_key=BNOAEBT3IZYZI6WXI&format=json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: !binary |-
14
+ T0s=
15
+ headers:
16
+ !binary "RGF0ZQ==":
17
+ - !binary |-
18
+ RnJpLCAwNyBNYXIgMjAxNCAwMzoyNzowNCBHTVQ=
19
+ !binary "Q29udGVudC1UeXBl":
20
+ - !binary |-
21
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
22
+ !binary "Q29udGVudC1MZW5ndGg=":
23
+ - !binary |-
24
+ ODU0
25
+ !binary "VmFyeQ==":
26
+ - !binary |-
27
+ QWNjZXB0LUVuY29kaW5n
28
+ !binary "WC1SZXF1ZXN0LUlk":
29
+ - !binary |-
30
+ MDJabVNaSmFRYXl4UlJ5S3JpcFBsQQ==
31
+ !binary "RXRhZw==":
32
+ - !binary |-
33
+ IjUzZTFlN2JiZTY5NzIyYTZlZGU2MmQ5MGI1Yzg3NmUwZWUzZGNjNWMi
34
+ !binary "WC1Xb3JrZXItTm9kZQ==":
35
+ - !binary |-
36
+ NzQ2ZTE6MjY4OTg=
37
+ !binary "WC1SYXRlbGltaXQtUmVtYWluaW5n":
38
+ - !binary |-
39
+ MTk=
40
+ !binary "U2VydmVy":
41
+ - !binary |-
42
+ VG9ybmFkb1NlcnZlci8zLjE=
43
+ !binary "WC1SYXRlbGltaXQtTGltaXQ=":
44
+ - !binary |-
45
+ MjA=
46
+ !binary "WC1BcGktS2V5":
47
+ - !binary |-
48
+ Qk5PQUVCVDNJWllaSTZXWEk=
49
+ !binary "Q2FjaGUtQ29udHJvbA==":
50
+ - !binary |-
51
+ bWF4LWFnZT04NjQwMA==
52
+ !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
53
+ - !binary |-
54
+ Kg==
55
+ !binary "WC1SYXRlbGltaXQtVXNlZA==":
56
+ - !binary |-
57
+ MQ==
58
+ !binary "Q29ubmVjdGlvbg==":
59
+ - !binary |-
60
+ S2VlcC1hbGl2ZQ==
61
+ !binary "S2VlcC1BbGl2ZQ==":
62
+ - !binary |-
63
+ dGltZW91dD0xNSwgbWF4PTEwMA==
64
+ !binary "Vmlh":
65
+ - !binary |-
66
+ MS4xIElELTAwMDA2Mjc1MDEyMjM3NDYgdXByb3h5LTI=
67
+ body:
68
+ encoding: ASCII-8BIT
69
+ string: !binary |-
70
+ eyJyZXNwb25zZSI6IHsic3RhdHVzIjogeyJ2ZXJzaW9uIjogIjQuMiIsICJj
71
+ b2RlIjogMCwgIm1lc3NhZ2UiOiAiU3VjY2VzcyJ9LCAiYXJ0aXN0cyI6IFt7
72
+ Im5hbWUiOiAiS2F0eSBQZXJyeSIsICJpZCI6ICJBUjBJVlRMMTE4N0I5QUQ1
73
+ MjAifSwgeyJuYW1lIjogIkF2aWNpaSIsICJpZCI6ICJBUldMQUVFMTIyQkNG
74
+ Q0EyNDUifSwgeyJuYW1lIjogIkJleW9uY8OpIiwgImlkIjogIkFSNjVLN0Ex
75
+ MTg3RkI0REFBNCJ9LCB7Im5hbWUiOiAiUGhhcnJlbGwiLCAiaWQiOiAiQVJX
76
+ WFNQTzEyNDFCOUM2QjFDIn0sIHsibmFtZSI6ICJNaWxleSBDeXJ1cyIsICJp
77
+ ZCI6ICJBUllBVkJTMTE4N0ZCNUI0NkMifSwgeyJuYW1lIjogIkltYWdpbmUg
78
+ RHJhZ29ucyIsICJpZCI6ICJBUlJWUkZQMTI2RkUwMjUzMjcifSwgeyJuYW1l
79
+ IjogIkVtaW5lbSIsICJpZCI6ICJBUlRIOTA0MTE4N0ZCNDNFMUYifSwgeyJu
80
+ YW1lIjogIlBpdGJ1bGwiLCAiaWQiOiAiQVJLOUJIRTExODdGQjNBQzlEIn0s
81
+ IHsibmFtZSI6ICJCZWNrIiwgImlkIjogIkFSQzJYUjExMTg3RkI1Q0M5NSJ9
82
+ LCB7Im5hbWUiOiAiT25lUmVwdWJsaWMiLCAiaWQiOiAiQVI3M1M0RzExODdC
83
+ OUEwM0MyIn0sIHsibmFtZSI6ICJEYWZ0IFB1bmsiLCAiaWQiOiAiQVJGOEhU
84
+ UTExODdCOUFFNjkzIn0sIHsibmFtZSI6ICJTaGFraXJhIiwgImlkIjogIkFS
85
+ NlBKOFIxMTg3RkI1QUQ3MCJ9LCB7Im5hbWUiOiAiTG9yZGUiLCAiaWQiOiAi
86
+ QVJVWEFLVzEzRDYxMEIwQTlCIn0sIHsibmFtZSI6ICJFbGxpZSBHb3VsZGlu
87
+ ZyIsICJpZCI6ICJBUktUVEpWMTI1OTJDREEwN0YifSwgeyJuYW1lIjogIk9u
88
+ ZSBEaXJlY3Rpb24iLCAiaWQiOiAiQVJaSEZBWTEzMDcwOEVFMzY2In1dfX0=
89
+ http_version:
90
+ recorded_at: Fri, 07 Mar 2014 03:27:07 GMT
91
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://developer.echonest.com/api/v4/artist/urls?api_key=BNOAEBT3IZYZI6WXI&format=json&name=Weezer
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Tue, 25 Mar 2014 19:27:58 GMT
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '411'
21
+ Vary:
22
+ - Accept-Encoding
23
+ X-Request-Id:
24
+ - 9+GeAlcQTCKxVobTmu+hOQ
25
+ Etag:
26
+ - ! '"d08d0b34bc126745b7819958c8c509f0693588cd"'
27
+ X-Worker-Node:
28
+ - 7cbef:23004
29
+ X-Ratelimit-Remaining:
30
+ - '19'
31
+ Server:
32
+ - TornadoServer/3.1
33
+ X-Ratelimit-Limit:
34
+ - '20'
35
+ X-Api-Key:
36
+ - BNOAEBT3IZYZI6WXI
37
+ Cache-Control:
38
+ - max-age=86400
39
+ Access-Control-Allow-Origin:
40
+ - ! '*'
41
+ X-Ratelimit-Used:
42
+ - '1'
43
+ Connection:
44
+ - Keep-alive
45
+ Keep-Alive:
46
+ - timeout=15, max=100
47
+ Via:
48
+ - 1.1 ID-0000627501223746 uproxy-2
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ! '{"response": {"status": {"version": "4.2", "code": 0, "message":
52
+ "Success"}, "urls": {"official_url": "http://www.weezer.com", "lastfm_url":
53
+ "http://www.last.fm/music/Weezer", "twitter_url": "https://twitter.com/Weezer",
54
+ "myspace_url": "http://www.myspace.com/weezer", "wikipedia_url": "http://en.wikipedia.org/wiki/Weezer",
55
+ "mb_url": "http://musicbrainz.org/artist/6fe07aa5-fec0-4eca-a456-f29bff451b04.html"}}}'
56
+ http_version:
57
+ recorded_at: Tue, 25 Mar 2014 19:27:31 GMT
58
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://developer.echonest.com/api/v4/artist/video?api_key=BNOAEBT3IZYZI6WXI&format=json&name=Weezer&results=1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Tue, 25 Mar 2014 17:51:04 GMT
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '422'
21
+ Vary:
22
+ - Accept-Encoding
23
+ X-Request-Id:
24
+ - 6kvvBucfQjOHDAAr7D9bpQ
25
+ Etag:
26
+ - ! '"d9db9d4a1e07cec93621ece5d32ff9673ed0b225"'
27
+ X-Worker-Node:
28
+ - 962d4:14760
29
+ X-Ratelimit-Remaining:
30
+ - '18'
31
+ Server:
32
+ - TornadoServer/3.1
33
+ X-Ratelimit-Limit:
34
+ - '20'
35
+ X-Api-Key:
36
+ - BNOAEBT3IZYZI6WXI
37
+ Cache-Control:
38
+ - max-age=86400
39
+ Access-Control-Allow-Origin:
40
+ - ! '*'
41
+ X-Ratelimit-Used:
42
+ - '2'
43
+ Connection:
44
+ - Keep-alive
45
+ Keep-Alive:
46
+ - timeout=15, max=100
47
+ Via:
48
+ - 1.1 ID-0000627501223746 uproxy-2
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ! '{"response": {"status": {"version": "4.2", "code": 0, "message":
52
+ "Success"}, "start": 0, "total": 744, "video": [{"title": "Weezer - I Just
53
+ Threw Out The Love of My Dreams", "url": "http://www.youtube.com/watch?v=CFXOas-fCq8&feature=youtube_gdata_player",
54
+ "site": "youtube.com", "date_found": "2014-03-22T00:00:00", "image_url": "http://i.ytimg.com/vi/CFXOas-fCq8/default.jpg",
55
+ "id": "611289c4d72f6e507694c75f4552f9b2"}]}}'
56
+ http_version:
57
+ recorded_at: Tue, 25 Mar 2014 17:50:37 GMT
58
+ recorded_with: VCR 2.8.0
@@ -3,6 +3,7 @@ require "bundler/setup"
3
3
  require_relative 'base'
4
4
  require_relative 'blog'
5
5
  require_relative 'biography'
6
+ require_relative 'video'
6
7
  require_relative 'foreign_id'
7
8
 
8
9
  module Echonest
@@ -26,6 +27,7 @@ module Echonest
26
27
  end
27
28
  end
28
29
 
30
+ # Stuff from blogspot, etc
29
31
  def blogs(options = { results: 1 })
30
32
  response = get_response(results: options[:results], name: @name)
31
33
 
@@ -34,6 +36,27 @@ module Echonest
34
36
  end
35
37
  end
36
38
 
39
+ # This appears to be from more "reputable" sources?
40
+ def news(options = { results: 1 })
41
+ response = get_response(results: options[:results], name: @name)
42
+
43
+ response[:news].collect do |b|
44
+ Blog.new(name: b[:name], site: b[:site], url: b[:url])
45
+ end
46
+ end
47
+
48
+ def video(options = { results: 1 })
49
+ response = get_response(results: options[:results], name: @name)
50
+
51
+ response[:video].collect do |v|
52
+ Video.new(title: v[:title], site: v[:site], url: v[:url], date_found: v[:date_found], image_url: v[:image_url])
53
+ end
54
+ end
55
+
56
+ def urls
57
+ get_response(name: @name)[:urls]
58
+ end
59
+
37
60
  def familiarity
38
61
  response = get_response(name: @name)
39
62
  response[entity_name.to_sym][__method__.to_sym]
@@ -72,9 +95,17 @@ module Echonest
72
95
  artists
73
96
  end
74
97
 
75
- def songs
98
+ def top_hottt(options = {})
99
+ artists = []
100
+ get_response(options)[:artists].each do |a|
101
+ artists << Artist.new(@api_key, a[:name], a[:foreign_ids], a[:id])
102
+ end
103
+ artists
104
+ end
105
+
106
+ def songs(options = { results: 15 })
76
107
  songs = []
77
- get_response(name: @name)[:songs].each do |s|
108
+ get_response(results: options[:results], name: @name)[:songs].each do |s|
78
109
  songs << { s[:id] => s[:title] }
79
110
  end
80
111
  songs
@@ -1,3 +1,3 @@
1
1
  module Echonest
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ module Echonest
2
+ class Video
3
+ attr_accessor :title, :site, :url, :date_found, :image_url
4
+ def initialize(options = {})
5
+ @title = options[:title]
6
+ @site = options[:site]
7
+ @url = options[:url]
8
+ @date_found = options[:date_found]
9
+ @image_url = options[:image_url]
10
+ end
11
+ end
12
+ end
@@ -17,14 +17,12 @@ describe Echonest::Artist do
17
17
  end
18
18
 
19
19
  describe '#entity_name' do
20
-
21
20
  it 'should always return artist' do
22
21
  VCR.use_cassette('entity_name') do
23
22
  a = Echonest::Artist.new('Weezer', '12345')
24
23
  a.entity_name.should eql 'artist'
25
24
  end
26
25
  end
27
-
28
26
  end
29
27
 
30
28
  describe '#biographies' do
@@ -70,6 +68,53 @@ describe Echonest::Artist do
70
68
 
71
69
  end
72
70
 
71
+ describe '#news' do
72
+
73
+ it 'should download a specified number of news articles' do
74
+ VCR.use_cassette('ten_news_articles') do
75
+ create_valid_artist
76
+ @a.news(results: 10).count.should be 10
77
+ end
78
+ end
79
+
80
+ it 'should return one news article by default' do
81
+ VCR.use_cassette('news') do
82
+ create_valid_artist
83
+ @a.news.count.should be 1
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ describe '#videos' do
90
+
91
+ it 'should download a specified number of video streams' do
92
+ VCR.use_cassette('ten_videos') do
93
+ create_valid_artist
94
+ @a.video(results: 10).count.should be 10
95
+ end
96
+ end
97
+
98
+ it 'should return one video by default' do
99
+ VCR.use_cassette('videos') do
100
+ create_valid_artist
101
+ @a.video.count.should be 1
102
+ end
103
+ end
104
+
105
+ end
106
+
107
+ describe '#urls' do
108
+
109
+ it 'should return a hash of urls' do
110
+ VCR.use_cassette('urls') do
111
+ create_valid_artist
112
+ @a.urls.should be_a Hash
113
+ end
114
+ end
115
+
116
+ end
117
+
73
118
  describe '#familiarity' do
74
119
 
75
120
  it 'should allow us to find out how familiar an artist is' do
@@ -103,11 +148,9 @@ describe Echonest::Artist do
103
148
  @a.hotttnesss(type: 'mainstream').should be_a Float
104
149
  end
105
150
  end
106
-
107
151
  end
108
152
 
109
153
  describe '#images' do
110
-
111
154
  it 'should allow us to get an array of urls' do
112
155
  VCR.use_cassette('images') do
113
156
  create_valid_artist
@@ -139,86 +182,103 @@ describe Echonest::Artist do
139
182
  end
140
183
  end
141
184
 
142
- end
143
-
144
- describe '#list_genres' do
185
+ end # /images
145
186
 
187
+ describe '#list_genres', vcr: {cassette_name: 'list_genres'} do
146
188
  it 'should return an array of acceptable genres' do
147
- VCR.use_cassette('list_genres') do
148
- create_valid_artist
149
- @a.list_genres.should be_a Array
150
- end
189
+ create_valid_artist
190
+ @a.list_genres.should be_a Array
151
191
  end
152
192
 
153
193
  it 'should return an array in the correct format' do
154
- VCR.use_cassette('list_genres') do
155
- create_valid_artist
156
- @a.list_genres.each do |g|
157
- g[:name].should be_a String
158
- end
194
+ create_valid_artist
195
+ @a.list_genres.each do |g|
196
+ g[:name].should be_a String
159
197
  end
160
198
  end
161
-
162
199
  end
163
200
 
164
- describe '#search' do
201
+ describe '#search', vcr: {cassette_name: 'search'} do
165
202
  it 'should return an Array of artists' do
166
- VCR.use_cassette('search') do
167
- create_valid_artist
168
- @a.search.should be_a Array
169
- end
203
+ create_valid_artist
204
+ @a.search.should be_a Array
170
205
  end
171
206
 
172
207
  it 'should return an Artist object for each result' do
173
- VCR.use_cassette('search') do
174
- create_valid_artist
175
- @a.search.each do |k|
176
- k.class.should be Echonest::Artist
177
- end
208
+ create_valid_artist
209
+ @a.search.each do |k|
210
+ k.class.should be Echonest::Artist
178
211
  end
179
212
  end
180
213
 
181
214
  it 'should fill in id of each returned artist' do
182
- VCR.use_cassette('search') do
183
- create_valid_artist
184
- @a.search.each do |k|
185
- k.id.should_not be_nil
186
- end
215
+ create_valid_artist
216
+ @a.search.each do |k|
217
+ k.id.should_not be_nil
187
218
  end
188
219
  end
189
220
 
190
- it 'should search the specified bucket' do
191
- VCR.use_cassette('search_2') do
221
+ context 'with bucket', vcr: {cassette_name: 'search_2'} do
222
+ it 'should search the specified bucket' do
192
223
  create_valid_artist
193
224
  results = @a.search(bucket: "id:musicbrainz")
194
225
  foreign_id = results.first.foreign_ids.first
195
226
  foreign_id.catalog.should eq("musicbrainz")
196
227
  end
197
228
  end
198
- end
229
+ end # /search
199
230
 
200
- describe '#songs' do
231
+ describe '#top_hottt', vcr: {cassette_name: 'top_hottt'} do
232
+ it 'should return an Array of artists' do
233
+ create_valid_artist
234
+ @a.top_hottt.should be_a Array
235
+ end
201
236
 
202
- it 'should return an Array of a Hash of songs' do
203
- VCR.use_cassette('songs') do
204
- create_valid_artist
205
- @a.songs.should be_a Array
237
+ it 'should return an Artist object for each result' do
238
+ create_valid_artist
239
+ @a.top_hottt.each do |k|
240
+ k.class.should be Echonest::Artist
206
241
  end
207
242
  end
208
243
 
209
- it 'should return a valid hash for each song' do
210
- VCR.use_cassette('songs') do
211
- create_valid_artist
212
- @a.songs.each do |k|
213
- k.should be_a Hash
214
- end
244
+ it 'should fill in id of each returned artist' do
245
+ create_valid_artist
246
+ @a.top_hottt.each do |k|
247
+ k.id.should_not be_nil
215
248
  end
216
249
  end
217
250
 
251
+ it 'should only make one network request' do
252
+ create_valid_artist
253
+ @a.expects(:get_response).times(1).returns({:artists=>[]})
254
+ artists = @a.top_hottt
255
+ artists.should eq([])
256
+ end
257
+
258
+ end # /top_hottt
259
+
260
+ describe '#songs', vcr: {cassette_name: 'songs'} do
261
+ it 'should return an Array of a Hash of songs' do
262
+ create_valid_artist
263
+ @a.songs.should be_a Array
264
+ end
265
+
266
+ it 'should return a valid hash for each song' do
267
+ create_valid_artist
268
+ @a.songs.each do |k|
269
+ k.should be_a Hash
270
+ end
271
+ end
272
+ it 'should be able to fetch more than the default amount' do
273
+ VCR.use_cassette('songs_more') do
274
+ @a = Echonest::Artist.new('BNOAEBT3IZYZI6WXI', 'Bob Marley')
275
+ songs = @a.songs(results: 20)
276
+ songs.size.should be > 15
277
+ end
278
+ end
218
279
  end
219
280
 
220
281
  describe "#profile" do
221
-
222
282
  it 'should return an artist profile given an id' do
223
283
  VCR.use_cassette('profile') do
224
284
  @a = Echonest::Artist.new('BNOAEBT3IZYZI6WXI', nil, nil, 'ARH6W4X1187B99274F')
@@ -227,45 +287,35 @@ describe Echonest::Artist do
227
287
  artist.name.should eq "Radiohead"
228
288
  end
229
289
  end
230
-
231
290
  end
232
291
 
233
- describe '#terms' do
234
-
292
+ describe '#terms', vcr: {cassette_name: 'terms'} do
235
293
  it 'should return an array of hashes of terms' do
236
- VCR.use_cassette('terms') do
237
- create_valid_artist_with_id
238
- @a.terms.should be_a Array
239
- end
294
+ create_valid_artist_with_id
295
+ @a.terms.should be_a Array
240
296
  end
241
297
 
242
298
  it 'should return valid hash for each term' do
243
- VCR.use_cassette('terms') do
244
- create_valid_artist_with_id
245
- @a.terms.each do |k|
246
- k.should be_a Hash
247
- end
299
+ create_valid_artist_with_id
300
+ @a.terms.each do |k|
301
+ k.should be_a Hash
248
302
  end
249
303
  end
250
304
 
251
305
  it 'should return modern rock for Radiohead' do
252
- VCR.use_cassette('terms') do
253
- create_valid_artist_with_id
254
- @a.terms.map{|t| t[:name]}.should include("modern rock")
255
- end
306
+ create_valid_artist_with_id
307
+ @a.terms.map{|t| t[:name]}.should include("modern rock")
256
308
  end
257
309
 
258
310
  it 'should work even when artist has both name and id' do
259
311
  # If we try, echonest will respond with error:
260
312
  # 'limit - Only one of \"name\" or \"id\" is allowed'
261
- VCR.use_cassette('terms') do
262
- create_valid_artist_with_id
263
- @a.name = "Weezer"
264
- expect {
265
- @a.terms
266
- }.to_not raise_error
267
- end
313
+ create_valid_artist_with_id
314
+ @a.name = "Weezer"
315
+ expect {
316
+ @a.terms
317
+ }.to_not raise_error
268
318
  end
319
+ end # /terms
269
320
 
270
- end
271
321
  end