echonest-ruby-api 0.1.5 → 0.2
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.
- data/Gemfile +2 -1
- data/README.md +6 -3
- data/echonest-ruby-api.gemspec +1 -0
- data/fixtures/vcr_cassettes/profile.yml +53 -0
- data/fixtures/vcr_cassettes/terms.yml +77 -0
- data/lib/echonest-ruby-api/artist.rb +19 -9
- data/lib/echonest-ruby-api/biography.rb +2 -12
- data/lib/echonest-ruby-api/blog.rb +2 -15
- data/lib/echonest-ruby-api/version.rb +1 -1
- data/spec/artist_spec.rb +44 -1
- data/spec/spec_helper.rb +6 -1
- metadata +20 -2
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Require the gem in your file:
|
|
|
33
33
|
|
|
34
34
|
Create an instance of an object
|
|
35
35
|
|
|
36
|
-
artist = Echonest::Artist.new('
|
|
36
|
+
artist = Echonest::Artist.new('YOUR-API-KEY', 'Weezer')
|
|
37
37
|
|
|
38
38
|
Then you have access to a bunch of methods:
|
|
39
39
|
|
|
@@ -126,5 +126,8 @@ Testing is done using RSpec. Just run `guard` in the root directory and it'll ru
|
|
|
126
126
|
|
|
127
127
|
## Contributors
|
|
128
128
|
|
|
129
|
-
Max Woolf (me!)
|
|
130
|
-
abdyer
|
|
129
|
+
* Max Woolf (me!)
|
|
130
|
+
* abdyer
|
|
131
|
+
* garethrees
|
|
132
|
+
* jordanpoulton
|
|
133
|
+
* makersacademy
|
data/echonest-ruby-api.gemspec
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: http://developer.echonest.com/api/v4/artist/profile?api_key=BNOAEBT3IZYZI6WXI&format=json&id=ARH6W4X1187B99274F&name=
|
|
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, 16 Apr 2013 12:06:04 GMT
|
|
17
|
+
Content-Type:
|
|
18
|
+
- application/json; charset=utf-8
|
|
19
|
+
Content-Length:
|
|
20
|
+
- '138'
|
|
21
|
+
Vary:
|
|
22
|
+
- Accept-Encoding
|
|
23
|
+
X-Request-Id:
|
|
24
|
+
- S///jt5dQWqENJNsMyWKVg
|
|
25
|
+
Etag:
|
|
26
|
+
- '"aebecfa5ec35629c80f20d15927d4908b4167f44"'
|
|
27
|
+
X-Worker-Node:
|
|
28
|
+
- 962d4:4638
|
|
29
|
+
X-Ratelimit-Remaining:
|
|
30
|
+
- '19'
|
|
31
|
+
Server:
|
|
32
|
+
- TornadoServer/2.4.1
|
|
33
|
+
X-Ratelimit-Limit:
|
|
34
|
+
- '20'
|
|
35
|
+
Cache-Control:
|
|
36
|
+
- max-age=86400
|
|
37
|
+
Access-Control-Allow-Origin:
|
|
38
|
+
- '*'
|
|
39
|
+
X-Ratelimit-Used:
|
|
40
|
+
- '1'
|
|
41
|
+
Connection:
|
|
42
|
+
- Keep-alive
|
|
43
|
+
Keep-Alive:
|
|
44
|
+
- timeout=15, max=100
|
|
45
|
+
Via:
|
|
46
|
+
- 1.1 ID-0000627501223666 uproxy-3
|
|
47
|
+
body:
|
|
48
|
+
encoding: UTF-8
|
|
49
|
+
string: '{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"},
|
|
50
|
+
"artist": {"id": "ARH6W4X1187B99274F", "name": "Radiohead"}}}'
|
|
51
|
+
http_version:
|
|
52
|
+
recorded_at: Tue, 16 Apr 2013 12:06:09 GMT
|
|
53
|
+
recorded_with: VCR 2.4.0
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: http://developer.echonest.com/api/v4/artist/terms?api_key=BNOAEBT3IZYZI6WXI&format=json&id=ARH6W4X1187B99274F&name=
|
|
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, 16 Apr 2013 15:36:58 GMT
|
|
17
|
+
Content-Type:
|
|
18
|
+
- application/json; charset=utf-8
|
|
19
|
+
Content-Length:
|
|
20
|
+
- '2111'
|
|
21
|
+
Vary:
|
|
22
|
+
- Accept-Encoding
|
|
23
|
+
X-Request-Id:
|
|
24
|
+
- gXpEgeizQAGGst47meOWAQ
|
|
25
|
+
Etag:
|
|
26
|
+
- ! '"6c7ad38226a2cb3f6808fed206c128221da1472e"'
|
|
27
|
+
X-Worker-Node:
|
|
28
|
+
- d1c7d:18043
|
|
29
|
+
X-Ratelimit-Remaining:
|
|
30
|
+
- '19'
|
|
31
|
+
Server:
|
|
32
|
+
- TornadoServer/2.4.1
|
|
33
|
+
X-Ratelimit-Limit:
|
|
34
|
+
- '20'
|
|
35
|
+
Cache-Control:
|
|
36
|
+
- max-age=86400
|
|
37
|
+
Access-Control-Allow-Origin:
|
|
38
|
+
- ! '*'
|
|
39
|
+
X-Ratelimit-Used:
|
|
40
|
+
- '1'
|
|
41
|
+
Connection:
|
|
42
|
+
- Keep-alive
|
|
43
|
+
Keep-Alive:
|
|
44
|
+
- timeout=15, max=100
|
|
45
|
+
Via:
|
|
46
|
+
- 1.1 ID-0000627501223666 uproxy-3
|
|
47
|
+
body:
|
|
48
|
+
encoding: US-ASCII
|
|
49
|
+
string: ! '{"response": {"status": {"version": "4.2", "code": 0, "message":
|
|
50
|
+
"Success"}, "start": 0, "terms": [{"frequency": 1.0, "name": "rock", "weight":
|
|
51
|
+
1.0}, {"frequency": 0.32362762914965709, "name": "alternative rock", "weight":
|
|
52
|
+
0.69780927835051543}, {"frequency": 0.44937160189619696, "name": "electronic",
|
|
53
|
+
"weight": 0.68547496318114876}, {"frequency": 0.30395783840385909, "name":
|
|
54
|
+
"alternative", "weight": 0.51113770250368185}, {"frequency": 0.3330351216068515,
|
|
55
|
+
"name": "pop", "weight": 0.41310751104565535}, {"frequency": 0.12701643032455379,
|
|
56
|
+
"name": "art rock", "weight": 0.37453976435935199}, {"frequency": 0.18900195035169701,
|
|
57
|
+
"name": "90s", "weight": 0.32041605301914583}, {"frequency": 0.15086233578978614,
|
|
58
|
+
"name": "electronica", "weight": 0.30660898379970547}, {"frequency": 0.15515439522510874,
|
|
59
|
+
"name": "experimental", "weight": 0.28194035346097202}, {"frequency": 0.11026300031196913,
|
|
60
|
+
"name": "modern rock", "weight": 0.27899484536082475}, {"frequency": 0.11311005144022887,
|
|
61
|
+
"name": "post-punk", "weight": 0.2766936671575847}, {"frequency": 0.1958486968107972,
|
|
62
|
+
"name": "jazz", "weight": 0.25717967599410896}, {"frequency": 0.076972709443209955,
|
|
63
|
+
"name": "british pop", "weight": 0.23205081001472755}, {"frequency": 0.07795958505745175,
|
|
64
|
+
"name": "experimental rock", "weight": 0.22984167893961707}, {"frequency":
|
|
65
|
+
0.11062690830619014, "name": "ambient", "weight": 0.22505522827687777}, {"frequency":
|
|
66
|
+
0.060773261607601083, "name": "british rock", "weight": 0.17396907216494845},
|
|
67
|
+
{"frequency": 0.043226336802103069, "name": "alternative pop rock", "weight":
|
|
68
|
+
0.17286450662739322}, {"frequency": 0.043338377308222591, "name": "indietronica",
|
|
69
|
+
"weight": 0.17249631811487481}, {"frequency": 0.067005410887189226, "name":
|
|
70
|
+
"grunge", "weight": 0.1639359351988218}, {"frequency": 0.069209522653945518,
|
|
71
|
+
"name": "progressive rock", "weight": 0.16053019145802652}, {"frequency":
|
|
72
|
+
0.082315134619655381, "name": "80s", "weight": 0.14202871870397643}, {"frequency":
|
|
73
|
+
0.085107639075017574, "name": "indie", "weight": 0.13871502209131076}, {"frequency":
|
|
74
|
+
0.070086224148814005, "name": "soundtrack", "weight": 0.12039764359351988}]}}'
|
|
75
|
+
http_version:
|
|
76
|
+
recorded_at: Tue, 16 Apr 2013 15:36:58 GMT
|
|
77
|
+
recorded_with: VCR 2.4.0
|
|
@@ -11,7 +11,8 @@ module Echonest
|
|
|
11
11
|
|
|
12
12
|
attr_accessor :id, :name, :foreign_ids
|
|
13
13
|
|
|
14
|
-
def initialize(api_key, name = nil, foreign_ids = nil)
|
|
14
|
+
def initialize(api_key, name = nil, foreign_ids = nil, id = nil)
|
|
15
|
+
@id = id
|
|
15
16
|
@name = name
|
|
16
17
|
@api_key = api_key
|
|
17
18
|
@foreign_ids = ForeignId.parse_array(foreign_ids) if foreign_ids
|
|
@@ -19,20 +20,18 @@ module Echonest
|
|
|
19
20
|
|
|
20
21
|
def biographies(options = { results: 1 })
|
|
21
22
|
response = get_response(results: options[:results], name: @name)
|
|
22
|
-
|
|
23
|
-
response[:biographies].
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
response[:biographies].collect do |b|
|
|
25
|
+
Biography.new(text: b[:text], site: b[:site], url: b[:url])
|
|
25
26
|
end
|
|
26
|
-
biographies
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def blogs(options = { results: 1 })
|
|
30
30
|
response = get_response(results: options[:results], name: @name)
|
|
31
|
-
|
|
32
|
-
response[:blogs].
|
|
33
|
-
|
|
31
|
+
|
|
32
|
+
response[:blogs].collect do |b|
|
|
33
|
+
Blog.new(name: b[:name], site: b[:site], url: b[:url])
|
|
34
34
|
end
|
|
35
|
-
blogs
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
def familiarity
|
|
@@ -75,5 +74,16 @@ module Echonest
|
|
|
75
74
|
songs
|
|
76
75
|
end
|
|
77
76
|
|
|
77
|
+
def profile(options = {})
|
|
78
|
+
options = {name: @name, id: @id}.merge(options)
|
|
79
|
+
artist_data = get_response(options)[:artist]
|
|
80
|
+
Artist.new(@api_key, artist_data[:name], artist_data[:foreign_ids], artist_data[:id])
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def terms(options = {})
|
|
84
|
+
options = {name: @name, id: @id}.merge(options)
|
|
85
|
+
get_response(options)[:terms]
|
|
86
|
+
end
|
|
87
|
+
|
|
78
88
|
end
|
|
79
89
|
end
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
class Biography
|
|
2
2
|
|
|
3
|
+
attr_accessor :text, :site, :url
|
|
4
|
+
|
|
3
5
|
def initialize(options = {})
|
|
4
6
|
@text = options[:text]
|
|
5
7
|
@site = options[:site]
|
|
6
8
|
@url = options[:url]
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
def text
|
|
10
|
-
@text
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def site
|
|
14
|
-
@site
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def url
|
|
18
|
-
@url
|
|
19
|
-
end
|
|
20
|
-
|
|
21
11
|
end
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
class Blog
|
|
2
|
+
|
|
3
|
+
attr_accessor :name, :summary, :url, :date_posted
|
|
2
4
|
def initialize(options = {})
|
|
3
5
|
@name = options[:name]
|
|
4
6
|
@summary = options[:summary]
|
|
@@ -6,19 +8,4 @@ class Blog
|
|
|
6
8
|
@date_posted = options[:date_posted]
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
def name
|
|
10
|
-
@name
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def summary
|
|
14
|
-
@summary
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def url
|
|
18
|
-
@url
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def date_posted
|
|
22
|
-
@date_posted
|
|
23
|
-
end
|
|
24
11
|
end
|
data/spec/artist_spec.rb
CHANGED
|
@@ -6,6 +6,10 @@ describe Echonest::Artist do
|
|
|
6
6
|
@a = Echonest::Artist.new('BNOAEBT3IZYZI6WXI', 'Weezer')
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def create_valid_artist_with_id
|
|
10
|
+
@a = Echonest::Artist.new('BNOAEBT3IZYZI6WXI', nil, nil, 'ARH6W4X1187B99274F')
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
|
|
10
14
|
it 'should allow an Artist to have a name' do
|
|
11
15
|
a = Echonest::Artist.new('12345', 'Weezer')
|
|
@@ -175,4 +179,43 @@ describe Echonest::Artist do
|
|
|
175
179
|
|
|
176
180
|
end
|
|
177
181
|
|
|
178
|
-
|
|
182
|
+
describe "#profile" do
|
|
183
|
+
|
|
184
|
+
it 'should return an artist profile given an id' do
|
|
185
|
+
VCR.use_cassette('profile') do
|
|
186
|
+
@a = Echonest::Artist.new('BNOAEBT3IZYZI6WXI', nil, nil, 'ARH6W4X1187B99274F')
|
|
187
|
+
artist = @a.profile
|
|
188
|
+
artist.should be_a Echonest::Artist
|
|
189
|
+
artist.name.should eq "Radiohead"
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
describe '#terms' do
|
|
196
|
+
|
|
197
|
+
it 'should return an array of hashes of terms' do
|
|
198
|
+
VCR.use_cassette('terms') do
|
|
199
|
+
create_valid_artist_with_id
|
|
200
|
+
@a.terms.should be_a Array
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it 'should return valid hash for each term' do
|
|
205
|
+
VCR.use_cassette('terms') do
|
|
206
|
+
create_valid_artist_with_id
|
|
207
|
+
@a.terms.each do |k|
|
|
208
|
+
k.should be_a Hash
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it 'should return modern rock for Radiohead' do
|
|
214
|
+
VCR.use_cassette('terms') do
|
|
215
|
+
create_valid_artist_with_id
|
|
216
|
+
@a.terms.map{|t| t[:name]}.should include("modern rock")
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
end
|
|
221
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
SimpleCov.start
|
|
1
3
|
require 'rubygems'
|
|
2
4
|
require 'bundler/setup'
|
|
3
5
|
require_relative '../lib/echonest-ruby-api/base.rb'
|
|
4
6
|
require 'echonest-ruby-api'
|
|
5
7
|
require 'vcr'
|
|
6
8
|
require 'webmock/rspec'
|
|
9
|
+
require 'coveralls'
|
|
10
|
+
|
|
11
|
+
Coveralls.wear!
|
|
7
12
|
|
|
8
13
|
RSpec.configure do |config|
|
|
9
14
|
|
|
@@ -14,4 +19,4 @@ VCR.configure do |c|
|
|
|
14
19
|
c.hook_into :webmock
|
|
15
20
|
# TODO: Get rid of this when possible!
|
|
16
21
|
c.allow_http_connections_when_no_cassette = true
|
|
17
|
-
end
|
|
22
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: echonest-ruby-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: '0.2'
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: httparty
|
|
@@ -139,6 +139,22 @@ dependencies:
|
|
|
139
139
|
- - ! '>='
|
|
140
140
|
- !ruby/object:Gem::Version
|
|
141
141
|
version: '0'
|
|
142
|
+
- !ruby/object:Gem::Dependency
|
|
143
|
+
name: coveralls
|
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
|
145
|
+
none: false
|
|
146
|
+
requirements:
|
|
147
|
+
- - ! '>='
|
|
148
|
+
- !ruby/object:Gem::Version
|
|
149
|
+
version: '0'
|
|
150
|
+
type: :development
|
|
151
|
+
prerelease: false
|
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
153
|
+
none: false
|
|
154
|
+
requirements:
|
|
155
|
+
- - ! '>='
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '0'
|
|
142
158
|
description: A simple ruby wrapper around the Echonest API
|
|
143
159
|
email:
|
|
144
160
|
- max.woolf@boxuk.com
|
|
@@ -164,6 +180,7 @@ files:
|
|
|
164
180
|
- fixtures/vcr_cassettes/playlist.yml
|
|
165
181
|
- fixtures/vcr_cassettes/playlist_next.yml
|
|
166
182
|
- fixtures/vcr_cassettes/playlist_next_2.yml
|
|
183
|
+
- fixtures/vcr_cassettes/profile.yml
|
|
167
184
|
- fixtures/vcr_cassettes/search.yml
|
|
168
185
|
- fixtures/vcr_cassettes/search_2.yml
|
|
169
186
|
- fixtures/vcr_cassettes/single_biography.yml
|
|
@@ -172,6 +189,7 @@ files:
|
|
|
172
189
|
- fixtures/vcr_cassettes/song_search_slow.yml
|
|
173
190
|
- fixtures/vcr_cassettes/songs.yml
|
|
174
191
|
- fixtures/vcr_cassettes/ten_blogs.yml
|
|
192
|
+
- fixtures/vcr_cassettes/terms.yml
|
|
175
193
|
- lib/echonest-ruby-api.rb
|
|
176
194
|
- lib/echonest-ruby-api/artist.rb
|
|
177
195
|
- lib/echonest-ruby-api/base.rb
|