echowrap 0.0.1

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.
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,403 @@
1
+ require 'helper'
2
+
3
+ describe Echowrap::API::TasteProfile do
4
+
5
+ before do
6
+ @client = new_test_client
7
+ end
8
+
9
+ describe "#taste_profile_create" do
10
+
11
+ before do
12
+ stub_post("/api/v4/catalog/create").
13
+ with(:body => {:api_key => 'AK', :name => "Favorite Artists of Paul", :type => 'artist'}).
14
+ to_return(:body => fixture("taste_profile/create.json"),
15
+ :headers => {:content_type => "application/json; charset=utf-8"})
16
+ end
17
+
18
+ it "requests the correct resource" do
19
+ @client.taste_profile_create(:api_key => 'AK', :name => "Favorite Artists of Paul", :type => 'artist')
20
+ expect(a_post("/api/v4/catalog/create").
21
+ with(:body => {:api_key => 'AK', :name => "Favorite Artists of Paul", :type => 'artist'})).
22
+ to have_been_made
23
+ end
24
+
25
+ it "returns a taste profile" do
26
+ taste_profile = @client.taste_profile_create(:api_key => 'AK', :name => "Favorite Artists of Paul", :type => 'artist')
27
+ expect(taste_profile).to be_a Echowrap::TasteProfile
28
+ expect(taste_profile.id).to eq 'CAUWCTB13EBA18ADAE'
29
+ end
30
+ end
31
+
32
+ describe "#taste_profile_update" do
33
+
34
+ before do
35
+ stub_post("/api/v4/catalog/update").
36
+ with(:body => {:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE', :data_type => "json", :data => fixture('taste_profile/update_request_data.json').read}).
37
+ to_return(:body => fixture("taste_profile/update.json"),
38
+ :headers => {:content_type => "application/json; charset=utf-8"})
39
+ end
40
+
41
+ it "requests the correct resource" do
42
+ @client.taste_profile_update(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE', :data => fixture('taste_profile/update_request_data.json').read)
43
+ expect(a_post("/api/v4/catalog/update").
44
+ with(:body => {:api_key => 'AK', :data_type => "json", :id => 'CAUWCTB13EBA18ADAE', :data => fixture('taste_profile/update_request_data.json').read})).
45
+ to have_been_made
46
+ end
47
+
48
+ it "returns a taste profile" do
49
+ taste_profile = @client.taste_profile_update(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE', :data => fixture('taste_profile/update_request_data.json').read)
50
+ expect(taste_profile).to be_a Echowrap::TasteProfile
51
+ expect(taste_profile.id).to eq 'd298131d5f189c73bd9a8ff706621443'
52
+ end
53
+ end
54
+
55
+ describe "#taste_profile_keyvalues" do
56
+
57
+ before do
58
+ stub_get("/api/v4/catalog/keyvalues").
59
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'}).
60
+ to_return(:body => fixture("taste_profile/keyvalues.json"),
61
+ :headers => {:content_type => "application/json; charset=utf-8"})
62
+ end
63
+
64
+ it "requests the correct resource" do
65
+ @client.taste_profile_keyvalues(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
66
+ expect(a_get("/api/v4/catalog/keyvalues").
67
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'})).
68
+ to have_been_made
69
+ end
70
+
71
+ it "returns a taste profile" do
72
+ taste_profile = @client.taste_profile_keyvalues(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
73
+ expect(taste_profile).to be_a Echowrap::TasteProfile
74
+ expect(taste_profile.keyvalues.cat_type).to eq 'persona'
75
+ end
76
+ end
77
+
78
+ describe "#taste_profile_list" do
79
+
80
+ before do
81
+ stub_get("/api/v4/catalog/list").
82
+ to_return(:body => fixture("taste_profile/list.json"),
83
+ :headers => {:content_type => "application/json; charset=utf-8"})
84
+ end
85
+
86
+ it "requests the correct resource" do
87
+ @client.taste_profile_list(:api_key => 'AK')
88
+ expect(a_get("/api/v4/catalog/list")).
89
+ to have_been_made
90
+ end
91
+
92
+ it "returns taste profiles" do
93
+ taste_profiles = @client.taste_profile_list(:api_key => 'AK')
94
+ expect(taste_profiles).to be_a Array
95
+ expect(taste_profiles.first.id).to eq 'CAZOFXZ13EB0258BD4'
96
+ end
97
+ end
98
+
99
+ describe "#taste_profile_delete" do
100
+
101
+ before do
102
+ stub_post("/api/v4/catalog/delete").
103
+ with(:body => {:api_key => 'AK', :id => "CAZOFXZ13EB0258BD4"}).
104
+ to_return(:body => fixture("taste_profile/delete.json"),
105
+ :headers => {:content_type => "application/json; charset=utf-8"})
106
+ end
107
+
108
+ it "requests the correct resource" do
109
+ @client.taste_profile_delete(:api_key => 'AK', :id => 'CAZOFXZ13EB0258BD4')
110
+ expect(a_post("/api/v4/catalog/delete").
111
+ with(:body => {:api_key => 'AK', :id => 'CAZOFXZ13EB0258BD4'})).
112
+ to have_been_made
113
+ end
114
+
115
+ it "returns a taste profile" do
116
+ taste_profile = @client.taste_profile_delete(:api_key => 'AK', :id => 'CAZOFXZ13EB0258BD4')
117
+ expect(taste_profile).to be_a Echowrap::TasteProfile
118
+ expect(taste_profile.id).to eq 'CAOFUDS12BB066268E'
119
+ end
120
+ end
121
+
122
+
123
+ describe "#taste_profile_profile" do
124
+
125
+ before do
126
+ stub_get("/api/v4/catalog/profile").
127
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'}).
128
+ to_return(:body => fixture("taste_profile/profile.json"),
129
+ :headers => {:content_type => "application/json; charset=utf-8"})
130
+ end
131
+
132
+ it "requests the correct resource" do
133
+ @client.taste_profile_profile(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
134
+ expect(a_get("/api/v4/catalog/profile").
135
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'})).
136
+ to have_been_made
137
+ end
138
+
139
+ it "returns a taste profile" do
140
+ taste_profile = @client.taste_profile_profile(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
141
+ expect(taste_profile).to be_a Echowrap::TasteProfile
142
+ expect(taste_profile.name).to eq 'top hot song catalog by ID'
143
+ end
144
+ end
145
+
146
+ describe "#taste_profile_status" do
147
+
148
+ before do
149
+ stub_get("/api/v4/catalog/status").
150
+ with(:query => {:ticket => 'e0ba094bbf98cd006283aa7de6780a83'}).
151
+ to_return(:body => fixture("taste_profile/status.json"),
152
+ :headers => {:content_type => "application/json; charset=utf-8"})
153
+ end
154
+
155
+ it "requests the correct resource" do
156
+ @client.taste_profile_status(:api_key => 'AK', :ticket => 'e0ba094bbf98cd006283aa7de6780a83')
157
+ expect(a_get("/api/v4/catalog/status").
158
+ with(:query => {:ticket => 'e0ba094bbf98cd006283aa7de6780a83'})).
159
+ to have_been_made
160
+ end
161
+
162
+ it "returns a taste status" do
163
+ taste_profile_status = @client.taste_profile_status(:api_key => 'AK', :ticket => 'e0ba094bbf98cd006283aa7de6780a83')
164
+ expect(taste_profile_status).to be_a Echowrap::Status
165
+ expect(taste_profile_status.ticket_status).to eq 'complete'
166
+ end
167
+
168
+ it "returns a taste status update info" do
169
+ taste_profile_status = @client.taste_profile_status(:api_key => 'AK', :ticket => 'e0ba094bbf98cd006283aa7de6780a83')
170
+ expect(taste_profile_status.update_info).to be_a Array
171
+ expect(taste_profile_status.update_info.first.info).to eq 'lookup failed'
172
+ end
173
+ end
174
+
175
+ describe "#taste_profile_read" do
176
+
177
+ before do
178
+ stub_get("/api/v4/catalog/read").
179
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'}).
180
+ to_return(:body => fixture("taste_profile/read.json"),
181
+ :headers => {:content_type => "application/json; charset=utf-8"})
182
+ end
183
+
184
+ it "requests the correct resource" do
185
+ @client.taste_profile_read(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
186
+ expect(a_get("/api/v4/catalog/read").
187
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'})).
188
+ to have_been_made
189
+ end
190
+
191
+ it "returns a taste profile" do
192
+ taste_profile = @client.taste_profile_read(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
193
+ expect(taste_profile).to be_a Echowrap::TasteProfile
194
+ expect(taste_profile.name).to eq 'top hot song catalog by ID'
195
+ end
196
+
197
+ it 'returns items that may be songs' do
198
+ taste_profile = @client.taste_profile_read(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
199
+ expect(taste_profile.items).to be_a Array
200
+ expect(taste_profile.items.first.song_name).to eq 'Intro'
201
+ end
202
+
203
+ end
204
+
205
+ describe "#taste_profile_play" do
206
+
207
+ before do
208
+ stub_get("/api/v4/catalog/play").
209
+ with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'}).
210
+ to_return(:body => fixture("taste_profile/play.json"),
211
+ :headers => {:content_type => "application/json; charset=utf-8"})
212
+ end
213
+
214
+ it "requests the correct resource" do
215
+ @client.taste_profile_play(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
216
+ expect(a_get("/api/v4/catalog/play")
217
+ .with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'},
218
+ ))
219
+ .to have_been_made
220
+ end
221
+
222
+ it "returns boolean with response result" do
223
+ result = @client.taste_profile_play(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
224
+ expect(result).to be_true
225
+ end
226
+ end
227
+
228
+ describe "#taste_profile_skip" do
229
+
230
+ before do
231
+ stub_get("/api/v4/catalog/skip").
232
+ with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'}).
233
+ to_return(:body => fixture("taste_profile/skip.json"),
234
+ :headers => {:content_type => "application/json; charset=utf-8"})
235
+ end
236
+
237
+ it "requests the correct resource" do
238
+ @client.taste_profile_skip(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
239
+ expect(a_get("/api/v4/catalog/skip")
240
+ .with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'},
241
+ ))
242
+ .to have_been_made
243
+ end
244
+
245
+ it "returns boolean with response result" do
246
+ result = @client.taste_profile_skip(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
247
+ expect(result).to be_true
248
+ end
249
+ end
250
+
251
+ describe "#taste_profile_ban" do
252
+
253
+ before do
254
+ stub_get("/api/v4/catalog/ban").
255
+ with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'}).
256
+ to_return(:body => fixture("taste_profile/ban.json"),
257
+ :headers => {:content_type => "application/json; charset=utf-8"})
258
+ end
259
+
260
+ it "requests the correct resource" do
261
+ @client.taste_profile_ban(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
262
+ expect(a_get("/api/v4/catalog/ban")
263
+ .with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'},
264
+ ))
265
+ .to have_been_made
266
+ end
267
+
268
+ it "returns boolean with response result" do
269
+ result = @client.taste_profile_ban(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
270
+ expect(result).to be_true
271
+ end
272
+ end
273
+
274
+ describe "#taste_profile_favorite" do
275
+
276
+ before do
277
+ stub_get("/api/v4/catalog/favorite").
278
+ with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'}).
279
+ to_return(:body => fixture("taste_profile/favorite.json"),
280
+ :headers => {:content_type => "application/json; charset=utf-8"})
281
+ end
282
+
283
+ it "requests the correct resource" do
284
+ @client.taste_profile_favorite(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
285
+ expect(a_get("/api/v4/catalog/favorite")
286
+ .with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid'},
287
+ ))
288
+ .to have_been_made
289
+ end
290
+
291
+ it "returns boolean with response result" do
292
+ result = @client.taste_profile_favorite(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid')
293
+ expect(result).to be_true
294
+ end
295
+ end
296
+
297
+ describe "#taste_profile_rate" do
298
+
299
+ before do
300
+ stub_get("/api/v4/catalog/rate").
301
+ with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid', :rating => 5}).
302
+ to_return(:body => fixture("taste_profile/rate.json"),
303
+ :headers => {:content_type => "application/json; charset=utf-8"})
304
+ end
305
+
306
+ it "requests the correct resource" do
307
+ @client.taste_profile_rate(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid', :rating => 5)
308
+ expect(a_get("/api/v4/catalog/rate")
309
+ .with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid', :rating => 5},
310
+ ))
311
+ .to have_been_made
312
+ end
313
+
314
+ it "returns boolean with response result" do
315
+ result = @client.taste_profile_rate(:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9', :item => 'myitemid', :rating => 5)
316
+ expect(result).to be_true
317
+ end
318
+ end
319
+
320
+ describe "#taste_profile_feed" do
321
+
322
+ before do
323
+ stub_get("/api/v4/catalog/feed").
324
+ with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9'}).
325
+ to_return(:body => fixture("taste_profile/feed.json"),
326
+ :headers => {:content_type => "application/json; charset=utf-8"})
327
+ end
328
+
329
+ it "requests the correct resource" do
330
+ @client.taste_profile_feed(:api_key => 'AK', :id => 'a8cddde7afdf4ac09b510aa1c1c50bf9')
331
+ expect(a_get("/api/v4/catalog/feed")
332
+ .with(:query => {:id => 'a8cddde7afdf4ac09b510aa1c1c50bf9'},
333
+ )).
334
+ to have_been_made
335
+ end
336
+
337
+ it "returns feeds" do
338
+ feeds = @client.taste_profile_feed(:api_key => 'AK', :id => 'a8cddde7afdf4ac09b510aa1c1c50bf9')
339
+ expect(feeds).to be_a Array
340
+ expect(feeds.first.id).to eq 'e124dae0b5da8c37bc287abd0dd41a86'
341
+ end
342
+
343
+ it "returns feed references" do
344
+ feeds = @client.taste_profile_feed(:api_key => 'AK', :id => 'a8cddde7afdf4ac09b510aa1c1c50bf9')
345
+ expect(feeds.first.references).to be_a Array
346
+ expect(feeds.first.references.first.artist_id).to eq 'AR6HLNH1187B990435'
347
+ end
348
+ end
349
+
350
+ describe "#taste_profile_similar" do
351
+
352
+ before do
353
+ stub_get("/api/v4/catalog/similar").
354
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE'}).
355
+ to_return(:body => fixture("taste_profile/similar.json"),
356
+ :headers => {:content_type => "application/json; charset=utf-8"})
357
+ end
358
+
359
+ it "requests the correct resource" do
360
+ @client.taste_profile_similar(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
361
+ expect(a_get("/api/v4/catalog/similar")
362
+ .with(:query => {:id => 'CAUWCTB13EBA18ADAE'},
363
+ )).
364
+ to have_been_made
365
+ end
366
+
367
+ it "returns similars" do
368
+ similars = @client.taste_profile_similar(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE')
369
+ expect(similars).to be_a Array
370
+ expect(similars.first.id).to eq 'CAOFUDS12BB066268E'
371
+ end
372
+
373
+ end
374
+
375
+ describe "#taste_profile_predict" do
376
+
377
+ before do
378
+ stub_get("/api/v4/catalog/predict").
379
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE', :category => 'adventurousness'}).
380
+ to_return(:body => fixture("taste_profile/predict.json"),
381
+ :headers => {:content_type => "application/json; charset=utf-8"})
382
+ end
383
+
384
+ it "requests the correct resource" do
385
+ @client.taste_profile_predict(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE', :category => 'adventurousness')
386
+ expect(a_get("/api/v4/catalog/predict").
387
+ with(:query => {:id => 'CAUWCTB13EBA18ADAE', :category => 'adventurousness'})).
388
+ to have_been_made
389
+ end
390
+
391
+ it "returns a taste profile" do
392
+ taste_profile = @client.taste_profile_predict(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE', :category => 'adventurousness')
393
+ expect(taste_profile).to be_a Echowrap::TasteProfile
394
+ expect(taste_profile.name).to eq "Tim's Test Profile"
395
+ end
396
+
397
+ it "returns taste profile predictions" do
398
+ taste_profile = @client.taste_profile_predict(:api_key => 'AK', :id => 'CAUWCTB13EBA18ADAE', :category => 'adventurousness')
399
+ expect(taste_profile.predictions).to be_an Array
400
+ expect(taste_profile.predictions.first.category).to eq "mainstreamness"
401
+ end
402
+ end
403
+ end
@@ -0,0 +1,167 @@
1
+ require 'helper'
2
+
3
+ describe Echowrap::API::Track do
4
+ before do
5
+ @client = new_test_client
6
+ end
7
+
8
+ describe "#track_upload" do
9
+
10
+ context "with track as url option" do
11
+ before do
12
+ stub_post("/api/v4/track/upload").
13
+ with(:body => {:api_key => 'AK', :url => "http://freedownloads.last.fm/download/494669779/Calgary.mp3"}).
14
+ to_return(:body => fixture("track/upload.json"),
15
+ :headers => {:content_type => "application/json; charset=utf-8"})
16
+ end
17
+
18
+ it "requests the correct resource" do
19
+ @client.track_upload(:url => "http://freedownloads.last.fm/download/494669779/Calgary.mp3")
20
+ expect(a_post("/api/v4/track/upload").
21
+ with(:body => {:api_key => 'AK', :url => 'http://freedownloads.last.fm/download/494669779/Calgary.mp3'})).
22
+ to have_been_made
23
+ end
24
+
25
+ it "returns a track" do
26
+ track = @client.track_upload(:url => "http://freedownloads.last.fm/download/494669779/Calgary.mp3")
27
+ expect(track).to be_a Echowrap::Track
28
+ expect(track.id).to eq 'TRGOVKX128F7FA5920'
29
+ end
30
+ end
31
+
32
+ context "with local audio file and using filetype option" do
33
+
34
+ before do
35
+ stub_post("/api/v4/track/upload").
36
+ to_return(:body => fixture("track/upload.json"),
37
+ :headers => {:content_type => "application/json; charset=utf-8"})
38
+ end
39
+
40
+ it 'requests the correct resource' do
41
+ @client.track_upload(:track => fixture('technolol-music.mp3'))
42
+ expect(a_post("/api/v4/track/upload")).to have_been_made
43
+ end
44
+
45
+ it "returns a track" do
46
+ track = @client.track_upload(:track => fixture('technolol-music.mp3'))
47
+ expect(track).to be_a Echowrap::Track
48
+ expect(track.id).to eq 'TRGOVKX128F7FA5920'
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+ describe "#track_profile" do
55
+ before do
56
+ stub_get("/api/v4/track/profile").
57
+ with(:query => {:id => 'TRTLKZV12E5AC92E11'}).
58
+ to_return(:body => fixture("track/profile.json"),
59
+ :headers => {:content_type => "application/json; charset=utf-8"})
60
+ end
61
+
62
+ it "requests the correct resource" do
63
+ @client.track_profile(:id => 'TRTLKZV12E5AC92E11')
64
+ expect(a_get("/api/v4/track/profile").
65
+ with(:query => {:id => 'TRTLKZV12E5AC92E11'})).
66
+ to have_been_made
67
+ end
68
+
69
+ it "returns a track" do
70
+ track = @client.track_profile(:id => 'TRTLKZV12E5AC92E11')
71
+ expect(track).to be_a Echowrap::Track
72
+ expect(track.id).to eq 'TRTLKZV12E5AC92E11'
73
+ end
74
+
75
+ it 'returns an audio summary with track' do
76
+ track = @client.track_profile(:id => 'TRTLKZV12E5AC92E11')
77
+ expect(track.audio_summary).to be_a Echowrap::AudioSummary
78
+ expect(track.audio_summary.key).to eq 1
79
+
80
+ end
81
+ end
82
+
83
+ describe "#track_analysis" do
84
+
85
+ before do
86
+ stub_request(:get, "http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs&api_key=AK").
87
+ to_return(:body => fixture("track/analysis.json"),
88
+ :headers => {:content_type => "application/json; charset=utf-8"})
89
+ end
90
+
91
+ it "requests the correct resource" do
92
+ @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
93
+ expect(a_request(:get, "http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs&api_key=AK")).
94
+ to have_been_made
95
+ end
96
+
97
+ it "returns an analysis" do
98
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
99
+ expect(analysis).to be_a Echowrap::Analysis
100
+ expect(analysis.id).to eq 1299731141
101
+ end
102
+
103
+ it 'returns a track as part of the analysis' do
104
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
105
+ track = analysis.track
106
+ expect(track).to be_a Echowrap::Track
107
+ expect(track.num_samples).to eq 5372342
108
+ end
109
+
110
+ it 'returns bars as part of the analysis' do
111
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
112
+ bars = analysis.bars
113
+ expect(bars).to be_a Array
114
+ expect(bars.count).to eq 74
115
+ bar = bars.first
116
+ expect(bar.id).to eq 'echowrap::bar_0.38205'
117
+ end
118
+
119
+ it 'returns beats as part of the analysis' do
120
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
121
+ beats = analysis.beats
122
+ expect(beats).to be_a Array
123
+ expect(beats.count).to eq 300
124
+ beat = beats.first
125
+ expect(beat.id).to eq 'echowrap::beat_0.38205'
126
+ end
127
+
128
+ it 'returns beats as part of the analysis' do
129
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
130
+ beats = analysis.beats
131
+ expect(beats).to be_a Array
132
+ expect(beats.count).to eq 300
133
+ beat = beats.first
134
+ expect(beat.id).to eq 'echowrap::beat_0.38205'
135
+ end
136
+
137
+ it 'returns sections as part of the analysis' do
138
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
139
+ sections = analysis.sections
140
+ expect(sections).to be_a Array
141
+ expect(sections.count).to eq 9
142
+ section = sections.first
143
+ expect(section.id).to eq 'echowrap::section_0.0'
144
+ end
145
+
146
+ it 'returns segments as part of the analysis' do
147
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
148
+ segments = analysis.segments
149
+ expect(segments).to be_a Array
150
+ expect(segments.count).to eq 683
151
+ segment = segments.first
152
+ expect(segment.id).to eq 'echowrap::segment_0.0'
153
+ end
154
+
155
+ it 'returns tatums as part of the analysis' do
156
+ analysis = @client.track_analysis(:url => 'http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367716357&Signature=dkZ4zsyf2%2BOuICu/veozEN5wWMs')
157
+ tatums = analysis.tatums
158
+ expect(tatums).to be_a Array
159
+ expect(tatums.count).to eq 599
160
+ tatum = tatums.first
161
+ expect(tatum.id).to eq 'echowrap::tatum_0.38205'
162
+ end
163
+
164
+
165
+ end
166
+
167
+ end
@@ -0,0 +1,119 @@
1
+ require 'helper'
2
+
3
+ describe Echowrap::Base do
4
+
5
+ #context "identity map enabled" do
6
+ #before do
7
+ #Echowrap.identity_map = Echowrap::IdentityMap
8
+ #object = Echowrap::Base.new(:id => 1)
9
+ #@base = Echowrap::Base.store(object)
10
+ #end
11
+
12
+ #after do
13
+ #Echowrap.identity_map = false
14
+ #end
15
+
16
+ #describe ".identity_map" do
17
+ #it "returns an instance of the identity map" do
18
+ #expect(Echowrap::Base.identity_map).to be_a Echowrap::IdentityMap
19
+ #end
20
+ #end
21
+
22
+ #describe ".fetch" do
23
+ #it "returns existing objects" do
24
+ #expect(Echowrap::Base.fetch(:id => 1)).to be
25
+ #end
26
+
27
+ #it "raises an error on objects that don't exist" do
28
+ #expect{Echowrap::Base.fetch(:id => 6)}.to raise_error Echowrap::Error::IdentityMapKeyError
29
+ #end
30
+ #end
31
+
32
+ #describe ".store" do
33
+ #it "stores Echowrap::Base objects" do
34
+ #object = Echowrap::Base.new(:id => 4)
35
+ #expect(Echowrap::Base.store(object)).to be_a Echowrap::Base
36
+ #end
37
+ #end
38
+
39
+ #describe ".fetch_or_new" do
40
+ #it "returns existing objects" do
41
+ #expect(Echowrap::Base.fetch_or_new(:id => 1)).to be
42
+ #end
43
+ #it "creates new objects and stores them" do
44
+ #expect(Echowrap::Base.fetch_or_new(:id => 2)).to be
45
+ #expect(Echowrap::Base.fetch(:id => 2)).to be
46
+ #end
47
+ #end
48
+
49
+ #describe "#[]" do
50
+ #it "calls methods using [] with symbol" do
51
+ #expect(@base[:object_id]).to be_an Integer
52
+ #end
53
+ #it "calls methods using [] with string" do
54
+ #expect(@base['object_id']).to be_an Integer
55
+ #end
56
+ #it "returns nil for missing method" do
57
+ #expect(@base[:foo]).to be_nil
58
+ #expect(@base['foo']).to be_nil
59
+ #end
60
+ #end
61
+
62
+ #describe "#to_hash" do
63
+ #it "returns a hash" do
64
+ #expect(@base.to_hash).to be_a Hash
65
+ #expect(@base.to_hash[:id]).to eq 1
66
+ #end
67
+ #end
68
+
69
+ #describe "identical objects" do
70
+ #it "have the same object_id" do
71
+ #expect(@base.object_id).to eq Echowrap::Base.fetch(:id => 1).object_id
72
+ #end
73
+ #end
74
+
75
+ #end
76
+
77
+ #context "identity map disabled" do
78
+
79
+ #before(:all) do
80
+ #Echowrap.identity_map = false
81
+ #end
82
+
83
+ #after(:all) do
84
+ #Echowrap.identity_map = Echowrap::IdentityMap
85
+ #end
86
+
87
+ #describe ".identity_map" do
88
+ #it "returns nil" do
89
+ #expect(Echowrap::Base.identity_map).to be_nil
90
+ #end
91
+ #end
92
+
93
+ #describe ".fetch" do
94
+ #it "returns nil" do
95
+ #expect(Echowrap::Base.fetch(:id => 1)).to be_nil
96
+ #end
97
+ #end
98
+
99
+ #describe ".store" do
100
+ #it "returns an instance of the object" do
101
+ #expect(Echowrap::Base.store(Echowrap::Base.new(:id => 1))).to be_a Echowrap::Base
102
+ #end
103
+ #end
104
+
105
+ #describe ".fetch_or_new" do
106
+ #it "creates new objects" do
107
+ #expect(Echowrap::Base.fetch_or_new(:id => 2)).to be
108
+ #expect(Echowrap.identity_map).to be_false
109
+ #end
110
+ #end
111
+ #end
112
+
113
+ #describe '#attrs' do
114
+ #it 'returns a hash of attributes' do
115
+ #expect(Echowrap::Base.new(:id => 1).attrs).to eq({:id => 1})
116
+ #end
117
+ #end
118
+
119
+ end