echonest-ruby-api 0.7.0 → 0.8.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.
- 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,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module Echonest
|
6
|
+
class Genre < Echonest::Base
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
def initialize(api_key, name = nil)
|
10
|
+
@api_key = api_key
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
def artists(options = {})
|
15
|
+
get_response(options.merge(name: @name))
|
16
|
+
end
|
17
|
+
|
18
|
+
def profile(options = {})
|
19
|
+
get_response(options.merge(name: @name))
|
20
|
+
end
|
21
|
+
|
22
|
+
def similar(options = {})
|
23
|
+
get_response(options.merge(name: @name))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.list(api_key, options = {})
|
27
|
+
Base.get_api_endpoint(api_key, 'genre/list', options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.search(api_key, options = {})
|
31
|
+
Base.get_api_endpoint(api_key, 'genre/search', options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/artist_spec.rb
CHANGED
@@ -85,7 +85,7 @@ describe Echonest::Artist do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
describe '#videos' do
|
90
90
|
|
91
91
|
it 'should download a specified number of video streams' do
|
@@ -103,18 +103,18 @@ describe Echonest::Artist do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
describe '#urls' do
|
108
|
-
|
108
|
+
|
109
109
|
it 'should return a hash of urls' do
|
110
110
|
VCR.use_cassette('urls') do
|
111
111
|
create_valid_artist
|
112
112
|
@a.urls.should be_a Hash
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
describe '#familiarity' do
|
119
119
|
|
120
120
|
it 'should allow us to find out how familiar an artist is' do
|
@@ -138,6 +138,18 @@ describe Echonest::Artist do
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
+
describe '#genres' do
|
142
|
+
it 'should allow us to find what genre an artist is in' do
|
143
|
+
VCR.use_cassette('genres', record: :new_episodes) do
|
144
|
+
create_valid_artist
|
145
|
+
@a.genres.should be_an Array
|
146
|
+
@a.genres.size.should > 0
|
147
|
+
@a.genres.should include('rock')
|
148
|
+
@a.genres.should include('alternative rock')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
141
153
|
describe '#hotttnesss' do
|
142
154
|
it 'should allow us to find out how hotttt an artist is' do
|
143
155
|
VCR.use_cassette('hotttnesss') do
|
@@ -228,6 +240,60 @@ describe Echonest::Artist do
|
|
228
240
|
end
|
229
241
|
end # /search
|
230
242
|
|
243
|
+
describe '#similar', vcr: {cassette_name: 'similar_artists'} do
|
244
|
+
it 'should return similar artists' do
|
245
|
+
create_valid_artist
|
246
|
+
@a.similar(results: 10).count.should be > 0
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'expect to return an array of artists' do
|
250
|
+
create_valid_artist
|
251
|
+
results = @a.similar(results: 10)
|
252
|
+
results.should be_a Array
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'expect to return name for each artist' do
|
256
|
+
create_valid_artist
|
257
|
+
names = []
|
258
|
+
results = @a.similar(results: 10)
|
259
|
+
results.each do |a|
|
260
|
+
a[:name].empty?.should eq false
|
261
|
+
a[:name].length.should be > 0
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'expect an id for each similar artist' do
|
266
|
+
create_valid_artist
|
267
|
+
ids = []
|
268
|
+
results = @a.similar(results: 10)
|
269
|
+
results.each do |a|
|
270
|
+
a[:id].empty?.should eq false
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
end # /similar
|
275
|
+
|
276
|
+
describe '#suggest', vcr: {cassette_name: 'suggest'} do
|
277
|
+
it 'should return an Array of artists' do
|
278
|
+
create_valid_artist
|
279
|
+
@a.suggest.should be_a Array
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'should return an Artist object for each result' do
|
283
|
+
create_valid_artist
|
284
|
+
@a.suggest.each do |k|
|
285
|
+
k.class.should be Echonest::Artist
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'should fill in id of each returned artist' do
|
290
|
+
create_valid_artist
|
291
|
+
@a.suggest.each do |k|
|
292
|
+
k.id.should_not be_nil
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end # /suggest
|
296
|
+
|
231
297
|
describe '#top_hottt', vcr: {cassette_name: 'top_hottt'} do
|
232
298
|
it 'should return an Array of artists' do
|
233
299
|
create_valid_artist
|
data/spec/genre_spec.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Echonest::Genre do
|
4
|
+
it 'should accept name for creation' do
|
5
|
+
g = Echonest::Genre.new('BNOAEBT3IZYZI6WXI', 'folk rock')
|
6
|
+
|
7
|
+
expect(g.name).to eq 'folk rock'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'instance methods' do
|
11
|
+
context 'with valid api key and name' do
|
12
|
+
before :all do
|
13
|
+
@genre = Echonest::Genre.new('BNOAEBT3IZYZI6WXI', 'folk rock')
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#artists' do
|
17
|
+
it 'returns a list of associated artists' do
|
18
|
+
VCR.use_cassette('genre_artists') do
|
19
|
+
artists = @genre.artists
|
20
|
+
|
21
|
+
expect(artists[:status][:message]).to eq 'Success'
|
22
|
+
expect(artists[:artists]).to include(id: 'ARVHQNN1187B9B9FA3',
|
23
|
+
name: 'Cat Stevens')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#profile' do
|
29
|
+
it 'returns a profile response given' do
|
30
|
+
VCR.use_cassette('genre_profile') do
|
31
|
+
profile = @genre.profile
|
32
|
+
|
33
|
+
expect(profile[:status][:message]).to eq 'Success'
|
34
|
+
expect(profile[:genres][0][:name]).to eq 'folk rock'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#similar' do
|
40
|
+
it 'returns a list of similar genres' do
|
41
|
+
VCR.use_cassette('genre_similar') do
|
42
|
+
genres = @genre.similar
|
43
|
+
|
44
|
+
expect(genres[:status][:message]).to eq 'Success'
|
45
|
+
expect(genres[:genres]).to include name: 'singer-songwriter', similarity: 0.708333
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'class methods' do
|
53
|
+
describe '#list' do
|
54
|
+
it 'returns a list of genres given valid api key' do
|
55
|
+
VCR.use_cassette('genre_list') do
|
56
|
+
genres = Echonest::Genre.list 'BNOAEBT3IZYZI6WXI'
|
57
|
+
|
58
|
+
expect(genres[:status][:message]).to eq 'Success'
|
59
|
+
expect(genres[:genres]).to include name: 'folk rock'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#search' do
|
65
|
+
it 'returns a list of genres related to search term given valid api key' do
|
66
|
+
VCR.use_cassette('genre_search') do
|
67
|
+
results = Echonest::Genre.search 'BNOAEBT3IZYZI6WXI',
|
68
|
+
name: 'folk rock'
|
69
|
+
|
70
|
+
expect(results[:status][:message]).to eq 'Success'
|
71
|
+
expect(results[:genres]).to include name: 'folk rock'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Woolf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -141,6 +141,11 @@ files:
|
|
141
141
|
- fixtures/vcr_cassettes/biographies.yml
|
142
142
|
- fixtures/vcr_cassettes/blogs.yml
|
143
143
|
- fixtures/vcr_cassettes/familiarity.yml
|
144
|
+
- fixtures/vcr_cassettes/genre_artists.yml
|
145
|
+
- fixtures/vcr_cassettes/genre_list.yml
|
146
|
+
- fixtures/vcr_cassettes/genre_profile.yml
|
147
|
+
- fixtures/vcr_cassettes/genre_search.yml
|
148
|
+
- fixtures/vcr_cassettes/genre_similar.yml
|
144
149
|
- fixtures/vcr_cassettes/genres.yml
|
145
150
|
- fixtures/vcr_cassettes/hotttnesss.yml
|
146
151
|
- fixtures/vcr_cassettes/images.yml
|
@@ -155,6 +160,7 @@ files:
|
|
155
160
|
- fixtures/vcr_cassettes/profile.yml
|
156
161
|
- fixtures/vcr_cassettes/search.yml
|
157
162
|
- fixtures/vcr_cassettes/search_2.yml
|
163
|
+
- fixtures/vcr_cassettes/similar_artists.yml
|
158
164
|
- fixtures/vcr_cassettes/single_biography.yml
|
159
165
|
- fixtures/vcr_cassettes/song_identify.yml
|
160
166
|
- fixtures/vcr_cassettes/song_profile.yml
|
@@ -162,6 +168,7 @@ files:
|
|
162
168
|
- fixtures/vcr_cassettes/song_search_slow.yml
|
163
169
|
- fixtures/vcr_cassettes/songs.yml
|
164
170
|
- fixtures/vcr_cassettes/songs_more.yml
|
171
|
+
- fixtures/vcr_cassettes/suggest.yml
|
165
172
|
- fixtures/vcr_cassettes/ten_blogs.yml
|
166
173
|
- fixtures/vcr_cassettes/ten_news_articles.yml
|
167
174
|
- fixtures/vcr_cassettes/ten_videos.yml
|
@@ -176,6 +183,7 @@ files:
|
|
176
183
|
- lib/echonest-ruby-api/blog.rb
|
177
184
|
- lib/echonest-ruby-api/error.rb
|
178
185
|
- lib/echonest-ruby-api/foreign_id.rb
|
186
|
+
- lib/echonest-ruby-api/genre.rb
|
179
187
|
- lib/echonest-ruby-api/playlist.rb
|
180
188
|
- lib/echonest-ruby-api/song.rb
|
181
189
|
- lib/echonest-ruby-api/version.rb
|
@@ -184,6 +192,7 @@ files:
|
|
184
192
|
- spec/base_spec.rb
|
185
193
|
- spec/error_spec.rb
|
186
194
|
- spec/foreign_id_spec.rb
|
195
|
+
- spec/genre_spec.rb
|
187
196
|
- spec/playlist_spec.rb
|
188
197
|
- spec/song_spec.rb
|
189
198
|
- spec/spec_helper.rb
|
@@ -207,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
216
|
version: '0'
|
208
217
|
requirements: []
|
209
218
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.
|
219
|
+
rubygems_version: 2.2.2
|
211
220
|
signing_key:
|
212
221
|
specification_version: 4
|
213
222
|
summary: A gem to get hold of some echonest stuff!
|
@@ -216,6 +225,7 @@ test_files:
|
|
216
225
|
- spec/base_spec.rb
|
217
226
|
- spec/error_spec.rb
|
218
227
|
- spec/foreign_id_spec.rb
|
228
|
+
- spec/genre_spec.rb
|
219
229
|
- spec/playlist_spec.rb
|
220
230
|
- spec/song_spec.rb
|
221
231
|
- spec/spec_helper.rb
|