echonest-ruby-api 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Guardfile +2 -2
- data/README.md +43 -15
- data/fixtures/vcr_cassettes/genre_artists.yml +68 -0
- data/fixtures/vcr_cassettes/genre_list.yml +392 -0
- data/fixtures/vcr_cassettes/genre_profile.yml +59 -0
- data/fixtures/vcr_cassettes/genre_search.yml +59 -0
- data/fixtures/vcr_cassettes/genre_similar.yml +70 -0
- data/fixtures/vcr_cassettes/similar_artists.yml +66 -0
- data/fixtures/vcr_cassettes/suggest.yml +66 -0
- data/lib/echonest-ruby-api.rb +1 -0
- data/lib/echonest-ruby-api/artist.rb +20 -2
- data/lib/echonest-ruby-api/base.rb +33 -29
- data/lib/echonest-ruby-api/genre.rb +34 -0
- data/lib/echonest-ruby-api/version.rb +1 -1
- data/spec/artist_spec.rb +71 -5
- data/spec/genre_spec.rb +76 -0
- metadata +13 -3
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://developer.echonest.com/api/v4/genre/profile?api_key=BNOAEBT3IZYZI6WXI&format=json&name=folk%20rock
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- '*/*'
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Thu, 18 Dec 2014 02:52:19 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
X-Request-Id:
|
30
|
+
- PBbxhmaBRS6OugGjjBOgAQ
|
31
|
+
X-Worker-Node:
|
32
|
+
- 0c0ba:19427
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '18'
|
35
|
+
Server:
|
36
|
+
- TornadoServer/3.1
|
37
|
+
X-Ratelimit-Limit:
|
38
|
+
- '20'
|
39
|
+
X-Api-Key:
|
40
|
+
- BNOAEBT3IZYZI6WXI
|
41
|
+
Cache-Control:
|
42
|
+
- max-age=86400
|
43
|
+
Access-Control-Allow-Origin:
|
44
|
+
- '*'
|
45
|
+
X-Ratelimit-Used:
|
46
|
+
- '2'
|
47
|
+
Connection:
|
48
|
+
- Keep-alive
|
49
|
+
Keep-Alive:
|
50
|
+
- timeout=15, max=100
|
51
|
+
Via:
|
52
|
+
- 1.1 ID-0000627501223746 uproxy-3
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: '{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"},
|
56
|
+
"genres": [{"name": "folk rock"}]}}'
|
57
|
+
http_version:
|
58
|
+
recorded_at: Thu, 18 Dec 2014 02:52:19 GMT
|
59
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://developer.echonest.com/api/v4/genre/search?api_key=BNOAEBT3IZYZI6WXI&format=json&name=folk%20rock
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- '*/*'
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Thu, 18 Dec 2014 02:58:41 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
X-Request-Id:
|
30
|
+
- doVHTVmmRLWutqL39Ibnbg
|
31
|
+
X-Worker-Node:
|
32
|
+
- 962d4:23274
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '17'
|
35
|
+
Server:
|
36
|
+
- TornadoServer/3.1
|
37
|
+
X-Ratelimit-Limit:
|
38
|
+
- '20'
|
39
|
+
X-Api-Key:
|
40
|
+
- BNOAEBT3IZYZI6WXI
|
41
|
+
Cache-Control:
|
42
|
+
- max-age=86400
|
43
|
+
Access-Control-Allow-Origin:
|
44
|
+
- '*'
|
45
|
+
X-Ratelimit-Used:
|
46
|
+
- '3'
|
47
|
+
Connection:
|
48
|
+
- Keep-alive
|
49
|
+
Keep-Alive:
|
50
|
+
- timeout=15, max=100
|
51
|
+
Via:
|
52
|
+
- 1.1 ID-0000627501223746 uproxy-2
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: '{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"},
|
56
|
+
"start": 0, "genres": [{"name": "folk rock"}], "total": 1}}'
|
57
|
+
http_version:
|
58
|
+
recorded_at: Thu, 18 Dec 2014 02:58:41 GMT
|
59
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://developer.echonest.com/api/v4/genre/similar?api_key=BNOAEBT3IZYZI6WXI&format=json&name=folk%20rock
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- '*/*'
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Thu, 18 Dec 2014 02:58:41 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
X-Request-Id:
|
30
|
+
- EqhJ+djOS3yrOsfpCYjnng
|
31
|
+
X-Worker-Node:
|
32
|
+
- 0c0ba:19426
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '19'
|
35
|
+
Server:
|
36
|
+
- TornadoServer/3.1
|
37
|
+
X-Ratelimit-Limit:
|
38
|
+
- '20'
|
39
|
+
X-Api-Key:
|
40
|
+
- BNOAEBT3IZYZI6WXI
|
41
|
+
Cache-Control:
|
42
|
+
- max-age=86400
|
43
|
+
Access-Control-Allow-Origin:
|
44
|
+
- '*'
|
45
|
+
X-Ratelimit-Used:
|
46
|
+
- '1'
|
47
|
+
Connection:
|
48
|
+
- Keep-alive
|
49
|
+
Keep-Alive:
|
50
|
+
- timeout=15, max=100
|
51
|
+
Via:
|
52
|
+
- 1.1 ID-0000627501223746 uproxy-2
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: '{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"},
|
56
|
+
"start": 0, "genres": [{"name": "singer-songwriter", "similarity": 0.70833299999999999},
|
57
|
+
{"name": "mellow gold", "similarity": 0.60763900000000004}, {"name": "traditional
|
58
|
+
folk", "similarity": 0.5}, {"name": "roots rock", "similarity": 0.45833299999999999},
|
59
|
+
{"name": "folk", "similarity": 0.42708299999999999}, {"name": "soft rock",
|
60
|
+
"similarity": 0.42013899999999998}, {"name": "country rock", "similarity":
|
61
|
+
0.38888899999999998}, {"name": "british folk", "similarity": 0.36805599999999999},
|
62
|
+
{"name": "folk-pop", "similarity": 0.36111100000000002}, {"name": "folk christmas",
|
63
|
+
"similarity": 0.23958299999999999}, {"name": "classic rock", "similarity":
|
64
|
+
0.190972}, {"name": "rock", "similarity": 0.17361099999999999}, {"name": "album
|
65
|
+
rock", "similarity": 0.17013900000000001}, {"name": "psychedelic rock", "similarity":
|
66
|
+
0.16319400000000001}, {"name": "british blues", "similarity": 0.125}], "total":
|
67
|
+
17}}'
|
68
|
+
http_version:
|
69
|
+
recorded_at: Thu, 18 Dec 2014 02:58:41 GMT
|
70
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,66 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://developer.echonest.com/api/v4/artist/similar?api_key=BNOAEBT3IZYZI6WXI&format=json&name=Weezer&results=10
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 11 Nov 2014 02:35:10 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
X-Request-Id:
|
30
|
+
- DO3eFGEYQpyngza8OtSZ4w
|
31
|
+
X-Worker-Node:
|
32
|
+
- 322a7:4365
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '19'
|
35
|
+
Server:
|
36
|
+
- TornadoServer/3.1
|
37
|
+
X-Ratelimit-Limit:
|
38
|
+
- '20'
|
39
|
+
X-Api-Key:
|
40
|
+
- BNOAEBT3IZYZI6WXI
|
41
|
+
Cache-Control:
|
42
|
+
- max-age=86400
|
43
|
+
Access-Control-Allow-Origin:
|
44
|
+
- "*"
|
45
|
+
X-Ratelimit-Used:
|
46
|
+
- '1'
|
47
|
+
Connection:
|
48
|
+
- Keep-alive
|
49
|
+
Keep-Alive:
|
50
|
+
- timeout=15, max=100
|
51
|
+
Via:
|
52
|
+
- 1.1 ID-0000627501223746 uproxy-3
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: '{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"},
|
56
|
+
"artists": [{"id": "ARQOST01187B9AC91A", "name": "Rivers Cuomo"}, {"id": "ARBMR171187B989A5E",
|
57
|
+
"name": "The Rentals"}, {"id": "ARP7ILI1187B9AE9F7", "name": "Phantom Planet"},
|
58
|
+
{"id": "AR6OJYP1187B9AE997", "name": "Jimmy Eat World"}, {"id": "ARDBSFT1187B9AC9C1",
|
59
|
+
"name": "Fountains of Wayne"}, {"id": "ARMR7TU1187FB37128", "name": "that
|
60
|
+
dog."}, {"id": "ARBAN8S1187FB4D22F", "name": "Ben Folds Five"}, {"id": "ARM454O1187B9B72B0",
|
61
|
+
"name": "Superdrag"}, {"id": "ARH9ZEH1187B98E01F", "name": "Harvey Danger"},
|
62
|
+
{"id": "ARXDFN01187B9AE80E", "name": "The Presidents of the United States
|
63
|
+
of America"}]}}'
|
64
|
+
http_version:
|
65
|
+
recorded_at: Tue, 11 Nov 2014 02:35:09 GMT
|
66
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,66 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://developer.echonest.com/api/v4/artist/suggest?api_key=BNOAEBT3IZYZI6WXI&format=json&name=Weezer
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Mon, 01 Dec 2014 11:18:28 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
X-Request-Id:
|
30
|
+
- BPbKUDVjTxqqVNFViXHnNw
|
31
|
+
X-Worker-Node:
|
32
|
+
- 89619:11853
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '19'
|
35
|
+
Server:
|
36
|
+
- TornadoServer/3.1
|
37
|
+
X-Ratelimit-Limit:
|
38
|
+
- '20'
|
39
|
+
X-Api-Key:
|
40
|
+
- BNOAEBT3IZYZI6WXI
|
41
|
+
Cache-Control:
|
42
|
+
- max-age=86400
|
43
|
+
Access-Control-Allow-Origin:
|
44
|
+
- "*"
|
45
|
+
X-Ratelimit-Used:
|
46
|
+
- '1'
|
47
|
+
Connection:
|
48
|
+
- Keep-alive
|
49
|
+
Keep-Alive:
|
50
|
+
- timeout=15, max=100
|
51
|
+
Via:
|
52
|
+
- 1.1 ID-0000627501223746 uproxy-2
|
53
|
+
body:
|
54
|
+
encoding: UTF-8
|
55
|
+
string: '{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"},
|
56
|
+
"artists": [{"id": "AR633SY1187B9AC3B9", "name": "Weezer"}, {"id": "ARRLJLF13221695F30",
|
57
|
+
"name": "Weezer, Hayley Williams"}, {"id": "ARHVIPZ122CC3B2537", "name": "Weezer
|
58
|
+
Tribute"}, {"id": "ARGGYKM13365906CDC", "name": "Weezer/Hayley Williams"},
|
59
|
+
{"id": "ARFLKGR13C1C2A6C75", "name": "Weezer Rasca"}, {"id": "AROXBRK148E394961D",
|
60
|
+
"name": "Jane Weezer"}, {"id": "ARTHPBI13A23CD07FD", "name": "Weezer / Hayley
|
61
|
+
Williams"}, {"id": "ARWHDKF12AF7D9BEBF", "name": "Grease Weezer"}, {"id":
|
62
|
+
"ARIVGRW134198DDE27", "name": "Matt Sharp (of Weezer"}, {"id": "ARIAWPS13C1C298E1A",
|
63
|
+
"name": "Weezer Rascal"}]}}'
|
64
|
+
http_version:
|
65
|
+
recorded_at: Mon, 01 Dec 2014 11:18:28 GMT
|
66
|
+
recorded_with: VCR 2.9.3
|
data/lib/echonest-ruby-api.rb
CHANGED
@@ -52,11 +52,11 @@ module Echonest
|
|
52
52
|
Video.new(title: v[:title], site: v[:site], url: v[:url], date_found: v[:date_found], image_url: v[:image_url])
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def urls
|
57
57
|
get_response(name: @name)[:urls]
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def familiarity
|
61
61
|
response = get_response(name: @name)
|
62
62
|
response[entity_name.to_sym][__method__.to_sym]
|
@@ -95,6 +95,24 @@ module Echonest
|
|
95
95
|
artists
|
96
96
|
end
|
97
97
|
|
98
|
+
def similar(options = { results: 20 })
|
99
|
+
artists = []
|
100
|
+
response = get('artist/similar', {name: @name, results: options[:results]})
|
101
|
+
response[:artists].each do |a|
|
102
|
+
artists << a
|
103
|
+
end
|
104
|
+
return artists
|
105
|
+
end
|
106
|
+
|
107
|
+
def suggest(options = {})
|
108
|
+
options = {name: @name}.merge(options)
|
109
|
+
artists = []
|
110
|
+
get_response(options)[:artists].each do |a|
|
111
|
+
artists << Artist.new(@api_key, a[:name], a[:foreign_ids], a[:id])
|
112
|
+
end
|
113
|
+
artists
|
114
|
+
end
|
115
|
+
|
98
116
|
def top_hottt(options = {})
|
99
117
|
artists = []
|
100
118
|
get_response(options)[:artists].each do |a|
|
@@ -23,20 +23,6 @@ module Echonest
|
|
23
23
|
"#{ entity_name }/#{ calling_method }"
|
24
24
|
end
|
25
25
|
|
26
|
-
# Gets the base URI for all API calls
|
27
|
-
#
|
28
|
-
# Returns a String
|
29
|
-
def self.base_uri
|
30
|
-
"http://developer.echonest.com/api/v#{ Base.version }/"
|
31
|
-
end
|
32
|
-
|
33
|
-
# The current version of the Echonest API to be supported.
|
34
|
-
#
|
35
|
-
# Returns a Fixnum
|
36
|
-
def self.version
|
37
|
-
4
|
38
|
-
end
|
39
|
-
|
40
26
|
# Performs a simple HTTP get on an API endpoint.
|
41
27
|
#
|
42
28
|
# Examples:
|
@@ -51,21 +37,7 @@ module Echonest
|
|
51
37
|
#
|
52
38
|
# Returns a response as a Hash
|
53
39
|
def get(endpoint, options = {})
|
54
|
-
|
55
|
-
format: "json")
|
56
|
-
|
57
|
-
httparty_options = { query_string_normalizer: HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER,
|
58
|
-
query: options }
|
59
|
-
|
60
|
-
response = HTTParty.get("#{ Base.base_uri }#{ endpoint }", httparty_options)
|
61
|
-
json = MultiJson.load(response.body, symbolize_keys: true)
|
62
|
-
response_code = json[:response][:status][:code]
|
63
|
-
|
64
|
-
if response_code.eql?(0)
|
65
|
-
json[:response]
|
66
|
-
else
|
67
|
-
raise Echonest::Error.new(response_code, response), "Error code #{ response_code }"
|
68
|
-
end
|
40
|
+
Base.get_api_endpoint(@api_key, endpoint, options)
|
69
41
|
end
|
70
42
|
|
71
43
|
# Cross-platform way of finding an executable in the $PATH.
|
@@ -82,5 +54,37 @@ module Echonest
|
|
82
54
|
return nil
|
83
55
|
end
|
84
56
|
|
57
|
+
# Gets the base URI for all API calls
|
58
|
+
#
|
59
|
+
# Returns a String
|
60
|
+
def self.base_uri
|
61
|
+
"http://developer.echonest.com/api/v#{version}/"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Gets an arbitrary Echonest endpoint
|
65
|
+
def self.get_api_endpoint(api_key, endpoint, options = {})
|
66
|
+
options.merge!(api_key: api_key,
|
67
|
+
format: "json")
|
68
|
+
httparty_options = { query_string_normalizer: HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER,
|
69
|
+
query: options }
|
70
|
+
|
71
|
+
response = HTTParty.get("#{ base_uri }#{ endpoint }", httparty_options)
|
72
|
+
json = MultiJson.load(response.body, symbolize_keys: true)
|
73
|
+
response_code = json[:response][:status][:code]
|
74
|
+
|
75
|
+
if response_code.eql?(0)
|
76
|
+
json[:response]
|
77
|
+
else
|
78
|
+
error = Echonest::Error.new(response_code, response)
|
79
|
+
raise error, "Error code #{response_code}: #{error.description}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# The current version of the Echonest API to be supported.
|
84
|
+
#
|
85
|
+
# Returns a Fixnum
|
86
|
+
def self.version
|
87
|
+
4
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|