echowrap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +16 -0
  3. data/Gemfile +13 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +111 -0
  6. data/Rakefile +1 -0
  7. data/echowrap.gemspec +24 -0
  8. data/lib/echowrap/analysis.rb +39 -0
  9. data/lib/echowrap/api/artist.rb +387 -0
  10. data/lib/echowrap/api/oauth.rb +25 -0
  11. data/lib/echowrap/api/playlist.rb +248 -0
  12. data/lib/echowrap/api/sandbox.rb +45 -0
  13. data/lib/echowrap/api/song.rb +111 -0
  14. data/lib/echowrap/api/taste_profile.rb +296 -0
  15. data/lib/echowrap/api/track.rb +64 -0
  16. data/lib/echowrap/api/utils.rb +57 -0
  17. data/lib/echowrap/artist.rb +73 -0
  18. data/lib/echowrap/asset.rb +12 -0
  19. data/lib/echowrap/audio_summary.rb +15 -0
  20. data/lib/echowrap/base.rb +88 -0
  21. data/lib/echowrap/biography.rb +13 -0
  22. data/lib/echowrap/blog.rb +8 -0
  23. data/lib/echowrap/call_list.rb +8 -0
  24. data/lib/echowrap/category_map.rb +8 -0
  25. data/lib/echowrap/client.rb +80 -0
  26. data/lib/echowrap/configurable.rb +84 -0
  27. data/lib/echowrap/default.rb +88 -0
  28. data/lib/echowrap/doc_counts.rb +8 -0
  29. data/lib/echowrap/echonest_id.rb +8 -0
  30. data/lib/echowrap/error/bad_gateway.rb +11 -0
  31. data/lib/echowrap/error/bad_request.rb +10 -0
  32. data/lib/echowrap/error/client_error.rb +35 -0
  33. data/lib/echowrap/error/configuration_error.rb +8 -0
  34. data/lib/echowrap/error/forbidden.rb +10 -0
  35. data/lib/echowrap/error/gateway_timeout.rb +11 -0
  36. data/lib/echowrap/error/internal_server_error.rb +11 -0
  37. data/lib/echowrap/error/not_acceptable.rb +10 -0
  38. data/lib/echowrap/error/not_found.rb +10 -0
  39. data/lib/echowrap/error/server_error.rb +28 -0
  40. data/lib/echowrap/error/service_unavailable.rb +11 -0
  41. data/lib/echowrap/error/too_many_requests.rb +12 -0
  42. data/lib/echowrap/error/unauthorized.rb +10 -0
  43. data/lib/echowrap/error/unprocessable_entity.rb +10 -0
  44. data/lib/echowrap/error.rb +32 -0
  45. data/lib/echowrap/familiarity.rb +8 -0
  46. data/lib/echowrap/feed.rb +14 -0
  47. data/lib/echowrap/foreign_id.rb +10 -0
  48. data/lib/echowrap/genre.rb +8 -0
  49. data/lib/echowrap/hotttnesss.rb +8 -0
  50. data/lib/echowrap/image.rb +15 -0
  51. data/lib/echowrap/item.rb +95 -0
  52. data/lib/echowrap/item_request.rb +8 -0
  53. data/lib/echowrap/keyvalues.rb +8 -0
  54. data/lib/echowrap/license.rb +10 -0
  55. data/lib/echowrap/location.rb +8 -0
  56. data/lib/echowrap/meta.rb +9 -0
  57. data/lib/echowrap/news_article.rb +8 -0
  58. data/lib/echowrap/options.rb +10 -0
  59. data/lib/echowrap/playlist.rb +47 -0
  60. data/lib/echowrap/prediction.rb +7 -0
  61. data/lib/echowrap/rate_limit.rb +47 -0
  62. data/lib/echowrap/reference.rb +8 -0
  63. data/lib/echowrap/request/multipart_with_file.rb +36 -0
  64. data/lib/echowrap/response/parse_json.rb +25 -0
  65. data/lib/echowrap/response/raise_error.rb +31 -0
  66. data/lib/echowrap/review.rb +8 -0
  67. data/lib/echowrap/rule.rb +8 -0
  68. data/lib/echowrap/sandbox.rb +11 -0
  69. data/lib/echowrap/seeds.rb +9 -0
  70. data/lib/echowrap/sequenced_data/bar.rb +4 -0
  71. data/lib/echowrap/sequenced_data/beat.rb +4 -0
  72. data/lib/echowrap/sequenced_data/section.rb +6 -0
  73. data/lib/echowrap/sequenced_data/segment.rb +4 -0
  74. data/lib/echowrap/sequenced_data/tatum.rb +4 -0
  75. data/lib/echowrap/sequenced_data.rb +12 -0
  76. data/lib/echowrap/song.rb +24 -0
  77. data/lib/echowrap/status.rb +12 -0
  78. data/lib/echowrap/taste_profile.rb +28 -0
  79. data/lib/echowrap/term.rb +8 -0
  80. data/lib/echowrap/track.rb +21 -0
  81. data/lib/echowrap/update_info.rb +8 -0
  82. data/lib/echowrap/urls.rb +9 -0
  83. data/lib/echowrap/version.rb +18 -0
  84. data/lib/echowrap/video.rb +7 -0
  85. data/lib/echowrap/years_active.rb +8 -0
  86. data/lib/echowrap.rb +78 -0
  87. data/spec/echonest/api/artist_spec.rb +901 -0
  88. data/spec/echonest/api/oauth_spec.rb +29 -0
  89. data/spec/echonest/api/playlist_spec.rb +274 -0
  90. data/spec/echonest/api/sandbox_spec.rb +67 -0
  91. data/spec/echonest/api/song_spec.rb +326 -0
  92. data/spec/echonest/api/taste_profile_spec.rb +403 -0
  93. data/spec/echonest/api/track_spec.rb +167 -0
  94. data/spec/echonest/base_spec.rb +119 -0
  95. data/spec/echonest/client_spec.rb +174 -0
  96. data/spec/echonest/error_spec.rb +20 -0
  97. data/spec/echonest/rate_limit_spec.rb +76 -0
  98. data/spec/echonest_spec.rb +65 -0
  99. data/spec/fixtures/artist/biographies.json +1 -0
  100. data/spec/fixtures/artist/blogs.json +1 -0
  101. data/spec/fixtures/artist/extract.json +1 -0
  102. data/spec/fixtures/artist/familiarity.json +1 -0
  103. data/spec/fixtures/artist/hotttnesss.json +1 -0
  104. data/spec/fixtures/artist/images.json +1 -0
  105. data/spec/fixtures/artist/list_genres.json +1 -0
  106. data/spec/fixtures/artist/list_terms.json +1 -0
  107. data/spec/fixtures/artist/news.json +1 -0
  108. data/spec/fixtures/artist/profile.json +1 -0
  109. data/spec/fixtures/artist/reviews.json +1 -0
  110. data/spec/fixtures/artist/search.json +1 -0
  111. data/spec/fixtures/artist/similar.json +1 -0
  112. data/spec/fixtures/artist/songs.json +1 -0
  113. data/spec/fixtures/artist/suggest.json +1 -0
  114. data/spec/fixtures/artist/terms.json +1 -0
  115. data/spec/fixtures/artist/top_hottt.json +1 -0
  116. data/spec/fixtures/artist/top_terms.json +1 -0
  117. data/spec/fixtures/artist/twitter.json +1 -0
  118. data/spec/fixtures/artist/urls.json +1 -0
  119. data/spec/fixtures/artist/video.json +1 -0
  120. data/spec/fixtures/billie_jean_fingerprint.txt +1 -0
  121. data/spec/fixtures/billie_jean_query.json +16 -0
  122. data/spec/fixtures/oauth/timestamp.json +1 -0
  123. data/spec/fixtures/playlist/basic.json +1 -0
  124. data/spec/fixtures/playlist/dynamic/create.json +1 -0
  125. data/spec/fixtures/playlist/dynamic/delete.json +1 -0
  126. data/spec/fixtures/playlist/dynamic/feedback.json +1 -0
  127. data/spec/fixtures/playlist/dynamic/info.json +1 -0
  128. data/spec/fixtures/playlist/dynamic/next.json +1 -0
  129. data/spec/fixtures/playlist/dynamic/restart.json +1 -0
  130. data/spec/fixtures/playlist/dynamic/steer.json +1 -0
  131. data/spec/fixtures/playlist/static.json +1 -0
  132. data/spec/fixtures/sandbox/access.json +19 -0
  133. data/spec/fixtures/sandbox/list.json +1 -0
  134. data/spec/fixtures/song/identify.json +19 -0
  135. data/spec/fixtures/song/profile.json +1 -0
  136. data/spec/fixtures/song/search.json +1 -0
  137. data/spec/fixtures/taste_profile/ban.json +9 -0
  138. data/spec/fixtures/taste_profile/create.json +1 -0
  139. data/spec/fixtures/taste_profile/delete.json +11 -0
  140. data/spec/fixtures/taste_profile/favorite.json +9 -0
  141. data/spec/fixtures/taste_profile/feed.json +1 -0
  142. data/spec/fixtures/taste_profile/keyvalues.json +4 -0
  143. data/spec/fixtures/taste_profile/list.json +1 -0
  144. data/spec/fixtures/taste_profile/play.json +9 -0
  145. data/spec/fixtures/taste_profile/predict.json +1 -0
  146. data/spec/fixtures/taste_profile/profile.json +1 -0
  147. data/spec/fixtures/taste_profile/rate.json +9 -0
  148. data/spec/fixtures/taste_profile/read.json +1 -0
  149. data/spec/fixtures/taste_profile/similar.json +14 -0
  150. data/spec/fixtures/taste_profile/skip.json +9 -0
  151. data/spec/fixtures/taste_profile/status.json +2 -0
  152. data/spec/fixtures/taste_profile/update.json +10 -0
  153. data/spec/fixtures/taste_profile/update_request_data.json +4 -0
  154. data/spec/fixtures/technolol-music.mp3 +0 -0
  155. data/spec/fixtures/track/analysis.json +3 -0
  156. data/spec/fixtures/track/profile.json +35 -0
  157. data/spec/fixtures/track/upload.json +21 -0
  158. data/spec/helper.rb +50 -0
  159. metadata +323 -0
@@ -0,0 +1,326 @@
1
+ require 'helper'
2
+
3
+ describe Echowrap::API::Song do
4
+
5
+ before do
6
+ @client = new_test_client
7
+ end
8
+
9
+ describe "#song_search" do
10
+
11
+ before do
12
+ stub_get("/api/v4/song/search").
13
+ with(:query => {
14
+ :results => 1,
15
+ :artist => 'radiohead',
16
+ :title => 'karma police'}).
17
+ to_return(:body => fixture("song/search.json"),
18
+ :headers => {:content_type => "application/json; charset=utf-8"})
19
+ end
20
+
21
+
22
+ it "requests the correct resource" do
23
+ @client.song_search(:results => 1,
24
+ :artist => 'radiohead',
25
+ :title => 'karma police')
26
+ expect(a_get("/api/v4/song/search")
27
+ .with(:query => {:results => 1,
28
+ :artist => 'radiohead',
29
+ :title => 'karma police'},
30
+ ))
31
+ .to have_been_made
32
+ end
33
+
34
+ it "returns songs" do
35
+ songs = @client.song_search(:results => 1,
36
+ :artist => 'radiohead',
37
+ :title => 'karma police')
38
+ expect(songs).to be_an Array
39
+ expect(songs.first.title).to eq "Karma Police"
40
+ end
41
+
42
+ it 'still returns an audio summary if bucket is not specified' do
43
+ songs = @client.song_search(:results => 1,
44
+ :artist => 'radiohead',
45
+ :title => 'karma police')
46
+ expect(songs.first.audio_summary).to be_an Echowrap::AudioSummary
47
+ end
48
+
49
+ it 'returns nil for any field of audio summary' do
50
+ songs = @client.song_search(:results => 1,
51
+ :artist => 'radiohead',
52
+ :title => 'karma police')
53
+ expect(songs.first.audio_summary.key).to be_nil
54
+ end
55
+
56
+
57
+ end
58
+
59
+ describe '#song_profile' do
60
+ before do
61
+ stub_get("/api/v4/song/profile").
62
+ with(:query => {:id => 'SODJXOA1313438FB61',
63
+ :bucket => ['artist_familiarity',
64
+ 'artist_hotttnesss',
65
+ 'artist_location',
66
+ 'audio_summary',
67
+ 'scores',
68
+ 'song_currency',
69
+ 'song_discovery',
70
+ 'song_hotttness',
71
+ 'song_type',
72
+ 'tracks',
73
+ 'id:7digital-US']}).
74
+ to_return(:body => fixture("song/profile.json"),
75
+ :headers => {:content_type => "application/json; charset=utf-8"})
76
+ end
77
+
78
+ it "requests the correct resource" do
79
+ @client.song_profile(:id => 'SODJXOA1313438FB61',
80
+ :bucket => ['artist_familiarity',
81
+ 'artist_hotttnesss',
82
+ 'artist_location',
83
+ 'audio_summary',
84
+ 'scores',
85
+ 'song_currency',
86
+ 'song_discovery',
87
+ 'song_hotttness',
88
+ 'song_type',
89
+ 'tracks',
90
+ 'id:7digital-US'])
91
+ expect(a_get("/api/v4/song/profile").
92
+ with(:query => {:id => 'SODJXOA1313438FB61',
93
+ :bucket => ['artist_familiarity',
94
+ 'artist_hotttnesss',
95
+ 'artist_location',
96
+ 'audio_summary',
97
+ 'scores',
98
+ 'song_currency',
99
+ 'song_discovery',
100
+ 'song_hotttness',
101
+ 'song_type',
102
+ 'tracks',
103
+ 'id:7digital-US']})).
104
+ to have_been_made
105
+ end
106
+
107
+ it "returns a song" do
108
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
109
+ :bucket => ['artist_familiarity',
110
+ 'artist_hotttnesss',
111
+ 'artist_location',
112
+ 'audio_summary',
113
+ 'scores',
114
+ 'song_currency',
115
+ 'song_discovery',
116
+ 'song_hotttness',
117
+ 'song_type',
118
+ 'tracks',
119
+ 'id:7digital-US'])
120
+ expect(song).to be_a Echowrap::Song
121
+ expect(song.id).to eq 'SODJXOA1313438FB61'
122
+ end
123
+
124
+ it "returns artist familiarity" do
125
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
126
+ :bucket => ['artist_familiarity',
127
+ 'artist_hotttnesss',
128
+ 'artist_location',
129
+ 'audio_summary',
130
+ 'scores',
131
+ 'song_currency',
132
+ 'song_discovery',
133
+ 'song_hotttness',
134
+ 'song_type',
135
+ 'tracks',
136
+ 'id:7digital-US'])
137
+ expect(song.artist_familiarity).to be_an Float
138
+ expect(song.artist_familiarity).to eq 0.892819
139
+ end
140
+
141
+ it "returns artist hotttnesss" do
142
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
143
+ :bucket => ['artist_familiarity',
144
+ 'artist_hotttnesss',
145
+ 'artist_location',
146
+ 'audio_summary',
147
+ 'scores',
148
+ 'song_currency',
149
+ 'song_discovery',
150
+ 'song_hotttness',
151
+ 'song_type',
152
+ 'tracks',
153
+ 'id:7digital-US'])
154
+ expect(song.artist_hotttnesss).to be_an Float
155
+ expect(song.artist_hotttnesss).to eq 0.625762
156
+ end
157
+
158
+ it "returns an artist location" do
159
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
160
+ :bucket => ['artist_familiarity',
161
+ 'artist_hotttnesss',
162
+ 'artist_location',
163
+ 'audio_summary',
164
+ 'scores',
165
+ 'song_currency',
166
+ 'song_discovery',
167
+ 'song_hotttness',
168
+ 'song_type',
169
+ 'tracks',
170
+ 'id:7digital-US'])
171
+ expect(song.artist_location).to be_an Echowrap::Location
172
+ expect(song.artist_location.location).to eq "Gary, IN, US"
173
+ end
174
+
175
+ it "returns an audio summary" do
176
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
177
+ :bucket => ['artist_familiarity',
178
+ 'artist_hotttnesss',
179
+ 'artist_location',
180
+ 'audio_summary',
181
+ 'scores',
182
+ 'song_currency',
183
+ 'song_discovery',
184
+ 'song_hotttness',
185
+ 'song_type',
186
+ 'tracks',
187
+ 'id:7digital-US'])
188
+ expect(song.audio_summary).to be_an Echowrap::AudioSummary
189
+ expect(song.audio_summary.audio_md5).to eq "77688ec91b91e8cf5e105049a4227be9"
190
+ end
191
+
192
+ it "returns song currency" do
193
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
194
+ :bucket => ['artist_familiarity',
195
+ 'artist_hotttnesss',
196
+ 'artist_location',
197
+ 'audio_summary',
198
+ 'scores',
199
+ 'song_currency',
200
+ 'song_discovery',
201
+ 'song_hotttness',
202
+ 'song_type',
203
+ 'tracks',
204
+ 'id:7digital-US'])
205
+ expect(song.song_currency).to be_an Float
206
+ expect(song.song_currency).to eq 0.062214422885901594
207
+ end
208
+
209
+ it "returns song discovery" do
210
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
211
+ :bucket => ['artist_familiarity',
212
+ 'artist_hotttnesss',
213
+ 'artist_location',
214
+ 'audio_summary',
215
+ 'scores',
216
+ 'song_currency',
217
+ 'song_discovery',
218
+ 'song_hotttness',
219
+ 'song_type',
220
+ 'tracks',
221
+ 'id:7digital-US'])
222
+ expect(song.song_discovery).to be_an Float
223
+ expect(song.song_discovery).to eq 0.0008134358711419619
224
+ end
225
+
226
+ it "returns song hotness" do
227
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
228
+ :bucket => ['artist_familiarity',
229
+ 'artist_hotttnesss',
230
+ 'artist_location',
231
+ 'audio_summary',
232
+ 'scores',
233
+ 'song_currency',
234
+ 'song_discovery',
235
+ 'song_hotttness',
236
+ 'song_type',
237
+ 'tracks',
238
+ 'id:7digital-US'])
239
+ expect(song.song_hotttnesss).to be_an Float
240
+ expect(song.song_hotttnesss).to eq 0.744413
241
+ end
242
+
243
+ it "returns song type" do
244
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
245
+ :bucket => ['artist_familiarity',
246
+ 'artist_hotttnesss',
247
+ 'artist_location',
248
+ 'audio_summary',
249
+ 'scores',
250
+ 'song_currency',
251
+ 'song_discovery',
252
+ 'song_hotttness',
253
+ 'song_type',
254
+ 'tracks',
255
+ 'id:7digital-US'])
256
+ expect(song.song_type).to be_an Array
257
+ expect(song.song_type.first).to eq 'studio'
258
+ end
259
+
260
+ it "returns tracks" do
261
+ song = @client.song_profile(:id => 'SODJXOA1313438FB61',
262
+ :bucket => ['artist_familiarity',
263
+ 'artist_hotttnesss',
264
+ 'artist_location',
265
+ 'audio_summary',
266
+ 'scores',
267
+ 'song_currency',
268
+ 'song_discovery',
269
+ 'song_hotttness',
270
+ 'song_type',
271
+ 'tracks',
272
+ 'id:7digital-US'])
273
+ expect(song.tracks).to be_an Array
274
+ expect(song.tracks.first.id).to eq 'TRDZFYM137EBC77532'
275
+ end
276
+
277
+ end
278
+
279
+ describe '#song_identify' do
280
+ context 'with POST' do
281
+ before do
282
+ stub_post("/api/v4/song/identify").
283
+ to_return(:body => fixture("song/identify.json"),
284
+ :headers => {:content_type => "application/json; charset=utf-8"})
285
+ end
286
+
287
+ it 'requests the correct resource' do
288
+ @client.song_identify(:query => fixture('billie_jean_query.json'))
289
+ expect(a_post("/api/v4/song/identify")).to have_been_made
290
+ end
291
+
292
+ it "returns a song" do
293
+ song = @client.song_identify(:query => fixture('billie_jean_query.json'))
294
+ expect(song).to be_a Echowrap::Song
295
+ expect(song.id).to eq 'SOKHYNL12A8C142FC7'
296
+ end
297
+
298
+
299
+ end
300
+
301
+ context 'with GET' do
302
+ before do
303
+ stub_get("/api/v4/song/identify").
304
+ with(:query => {:code => fixture('billie_jean_fingerprint.txt').read}).
305
+ to_return(:body => fixture("song/identify.json"),
306
+ :headers => {:content_type => "application/json; charset=utf-8"})
307
+ end
308
+
309
+ it 'requests the correct resource' do
310
+ @client.song_identify(:code => fixture('billie_jean_fingerprint.txt').read)
311
+ expect(a_get("/api/v4/song/identify").
312
+ with(:query => {:code => fixture('billie_jean_fingerprint.txt').read})).to have_been_made
313
+ end
314
+
315
+ it "returns a song" do
316
+ song = @client.song_identify(:code => fixture('billie_jean_fingerprint.txt').read)
317
+ expect(song).to be_a Echowrap::Song
318
+ expect(song.id).to eq 'SOKHYNL12A8C142FC7'
319
+ end
320
+
321
+ end
322
+
323
+ end
324
+
325
+
326
+ end