echowrap 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/echowrap/error/client_error.rb +1 -12
- data/lib/echowrap/version.rb +1 -1
- data/spec/echonest/client_spec.rb +0 -93
- data/spec/echonest/error_spec.rb +38 -0
- data/spec/fixtures/error_response.json +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0634ed5d2d365c11f726dc460204ddb5ccfe267b
|
4
|
+
data.tar.gz: e024bd59e708f57435a1ff3d38ee00398714e4ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bfdcd37bc277bf7e508372e8581d1bad7a3e368ee48e424186640ac98fd9897775bb114eb84b9120ae3fbac865e5a897442421f2f60b2c1aca8df35a759cbb4
|
7
|
+
data.tar.gz: 626c6b8c235a1b8326d4c24c7b35046eb3fda02e65d0e5a93f90b6a38ca83553fbb32eb4a5eedb8bed7fa00c5e7189010c5f94e53ccb05d20158f127acd2d753
|
@@ -16,18 +16,7 @@ module Echowrap
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def self.parse_error(body)
|
19
|
-
|
20
|
-
''
|
21
|
-
elsif body[:error]
|
22
|
-
body[:error]
|
23
|
-
elsif body[:errors]
|
24
|
-
first = Array(body[:errors]).first
|
25
|
-
if first.is_a?(Hash)
|
26
|
-
first[:message].chomp
|
27
|
-
else
|
28
|
-
first.chomp
|
29
|
-
end
|
30
|
-
end
|
19
|
+
body[:response][:status][:message]
|
31
20
|
end
|
32
21
|
|
33
22
|
end
|
data/lib/echowrap/version.rb
CHANGED
@@ -2,7 +2,7 @@ module Echowrap
|
|
2
2
|
class Version
|
3
3
|
MAJOR = 0 unless defined? Echowrap::Version::MAJOR
|
4
4
|
MINOR = 1 unless defined? Echowrap::Version::MINOR
|
5
|
-
PATCH =
|
5
|
+
PATCH = 2 unless defined? Echowrap::Version::PATCH
|
6
6
|
PRE = nil unless defined? Echowrap::Version::PRE
|
7
7
|
|
8
8
|
class << self
|
@@ -67,46 +67,6 @@ describe Echowrap::Client do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
# it "does not cache the screen name across clients" do
|
71
|
-
# stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
72
|
-
# client1 = Echowrap::Client.new
|
73
|
-
# expect(client1.verify_credentials.id).to eq 7505382
|
74
|
-
# stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
75
|
-
# client2 = Echowrap::Client.new
|
76
|
-
# expect(client2.verify_credentials.id).to eq 14100886
|
77
|
-
# end
|
78
|
-
#
|
79
|
-
# describe "#delete" do
|
80
|
-
# before do
|
81
|
-
# stub_delete("/custom/delete").with(:query => {:deleted => "object"})
|
82
|
-
# end
|
83
|
-
# it "allows custom delete requests" do
|
84
|
-
# subject.delete("/custom/delete", {:deleted => "object"})
|
85
|
-
# expect(a_delete("/custom/delete").with(:query => {:deleted => "object"})).to have_been_made
|
86
|
-
# end
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# describe "#put" do
|
90
|
-
# before do
|
91
|
-
# stub_put("/custom/put").with(:body => {:updated => "object"})
|
92
|
-
# end
|
93
|
-
# it "allows custom put requests" do
|
94
|
-
# subject.put("/custom/put", {:updated => "object"})
|
95
|
-
# expect(a_put("/custom/put").with(:body => {:updated => "object"})).to have_been_made
|
96
|
-
# end
|
97
|
-
# end
|
98
|
-
#
|
99
|
-
# describe "#credentials?" do
|
100
|
-
# it "returns true if all credentials are present" do
|
101
|
-
# client = Echowrap::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
102
|
-
# expect(client.credentials?).to be_true
|
103
|
-
# end
|
104
|
-
# it "returns false if any credentials are missing" do
|
105
|
-
# client = Echowrap::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT')
|
106
|
-
# expect(client.credentials?).to be_false
|
107
|
-
# end
|
108
|
-
# end
|
109
|
-
#
|
110
70
|
describe "#connection" do
|
111
71
|
it "looks like Faraday connection" do
|
112
72
|
expect(subject.send(:connection)).to respond_to(:run_request)
|
@@ -117,58 +77,5 @@ describe Echowrap::Client do
|
|
117
77
|
end
|
118
78
|
end
|
119
79
|
|
120
|
-
# describe "#request" do
|
121
|
-
# it "encodes the entire body when no uploaded media is present" do
|
122
|
-
# stub_post("/1.1/statuses/update.json").with(:body => {:status => "Update"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
123
|
-
# subject.update("Update")
|
124
|
-
# expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "Update"})).to have_been_made
|
125
|
-
# end
|
126
|
-
# it "encodes none of the body when uploaded media is present" do
|
127
|
-
# stub_post("/1.1/statuses/update_with_media.json")
|
128
|
-
# subject.update_with_media("Update", fixture("pbjt.gif"))
|
129
|
-
# expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
130
|
-
# end
|
131
|
-
# it "catches Faraday errors" do
|
132
|
-
# subject.stub!(:connection).and_raise(Faraday::Error::ClientError.new("Oops"))
|
133
|
-
# expect{subject.send(:request, :get, "/path")}.to raise_error Echowrap::Error::ClientError
|
134
|
-
# end
|
135
|
-
# it "catches MultiJson::DecodeError errors" do
|
136
|
-
# subject.stub!(:connection).and_raise(MultiJson::DecodeError.new("unexpected token", [], "<!DOCTYPE html>"))
|
137
|
-
# expect{subject.send(:request, :get, "/path")}.to raise_error Echowrap::Error::DecodeError
|
138
|
-
# end
|
139
|
-
# end
|
140
|
-
|
141
|
-
# describe "#oauth_auth_header" do
|
142
|
-
# it "creates the correct auth headers" do
|
143
|
-
# uri = "/1.1/direct_messages.json"
|
144
|
-
# authorization = subject.send(:oauth_auth_header, :get, uri)
|
145
|
-
# expect(authorization.options[:signature_method]).to eq "HMAC-SHA1"
|
146
|
-
# expect(authorization.options[:version]).to eq "1.0"
|
147
|
-
# expect(authorization.options[:consumer_key]).to eq "CK"
|
148
|
-
# expect(authorization.options[:consumer_secret]).to eq "CS"
|
149
|
-
# expect(authorization.options[:token]).to eq "OT"
|
150
|
-
# expect(authorization.options[:token_secret]).to eq "OS"
|
151
|
-
# end
|
152
|
-
# end
|
153
|
-
#
|
154
|
-
# describe "#bearer_auth_header" do
|
155
|
-
# subject do
|
156
|
-
# Echowrap::Client.new(:bearer_token => "BT")
|
157
|
-
# end
|
158
|
-
#
|
159
|
-
# it "creates the correct auth headers with supplied bearer_token" do
|
160
|
-
# uri = "/1.1/direct_messages.json"
|
161
|
-
# authorization = subject.send(:bearer_auth_header)
|
162
|
-
# expect(authorization).to eq "Bearer BT"
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
#
|
166
|
-
# describe "#bearer_token_credentials_auth_header" do
|
167
|
-
# it "creates the correct auth header with supplied consumer_key and consumer_secret" do
|
168
|
-
# uri = "/1.1/direct_messages.json"
|
169
|
-
# authorization = subject.send(:bearer_token_credentials_auth_header)
|
170
|
-
# expect(authorization).to eq "Basic #{Base64.strict_encode64("CK:CS")}"
|
171
|
-
# end
|
172
|
-
# end
|
173
80
|
end
|
174
81
|
|
data/spec/echonest/error_spec.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe Echowrap::Error do
|
4
|
+
before do
|
5
|
+
@client = new_test_client
|
6
|
+
end
|
4
7
|
|
5
8
|
describe "#initialize" do
|
6
9
|
it "wraps another error class" do
|
@@ -17,4 +20,39 @@ describe Echowrap::Error do
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
23
|
+
describe "#from_response" do
|
24
|
+
|
25
|
+
before do
|
26
|
+
stub_get("/api/v4/song/search").
|
27
|
+
with(:query => {
|
28
|
+
:results => 1,
|
29
|
+
:artist => 'radiohead',
|
30
|
+
:title => 'karma police',
|
31
|
+
:bucket => ['fakebucket']}).
|
32
|
+
to_return(:status => 400,
|
33
|
+
:body => fixture('error_response.json'))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return echowrap badrequest when 400 is returned" do
|
37
|
+
expect{@client.song_search(:results => 1,
|
38
|
+
:artist => 'radiohead',
|
39
|
+
:title => 'karma police',
|
40
|
+
:bucket => ['fakebucket'])}.to raise_error(Echowrap::Error::BadRequest)
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns an error with the echonest message parsed correctly" do
|
45
|
+
begin
|
46
|
+
@client.song_search(:results => 1,
|
47
|
+
:artist => 'radiohead',
|
48
|
+
:title => 'karma police',
|
49
|
+
:bucket => ['fakebucket'])
|
50
|
+
rescue Echowrap::Error::BadRequest => error
|
51
|
+
expect(error.message).to match(/bucket - Invalid parameter: bucket/)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
20
58
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"response": {"status": {"version": "4.2", "code": 5, "message": "bucket - Invalid parameter: bucket \"fakebucket\" is not one of \"song_hotttnesss\", \"song_hotttnesss_rank\", \"artist_familiarity\", \"artist_familiarity_rank\", \"artist_hotttnesss\", \"artist_hotttnesss_rank\", \"artist_discovery\", \"artist_discovery_rank\", \"audio_summary\", \"artist_location\", \"tracks\", \"scores\", \"song_type\", \"song_discovery\", \"song_discovery_rank\", \"song_currency\", \"song_currency_rank\", \"id:7digital-US\", \"id:7digital-AU\", \"id:7digital-UK\", \"id:facebook\", \"id:fma\", \"id:emi_open_collection\", \"id:emi_bluenote\", \"id:emi_artists\", \"id:twitter\", \"id:spotify-WW\", \"id:seatwave\", \"id:lyricfind-US\", \"id:jambase\", \"id:musixmatch-WW\", \"id:rdio-US\", \"id:rdio-AT\", \"id:rdio-AU\", \"id:rdio-BR\", \"id:rdio-CA\", \"id:rdio-CH\", \"id:rdio-DE\", \"id:rdio-DK\", \"id:rdio-ES\", \"id:rdio-FI\", \"id:rdio-FR\", \"id:rdio-IE\", \"id:rdio-IT\", \"id:rdio-NL\", \"id:rdio-NO\", \"id:rdio-NZ\", \"id:rdio-PT\", \"id:rdio-SE\", \"id:emi_electrospective\", \"id:rdio-WW\", \"id:rdio-EE\", \"id:rdio-LT\", \"id:rdio-LV\", \"id:rdio-IS\", \"id:rdio-BE\", \"id:rdio-MX\", \"id:seatgeek\", \"id:rdio-GB\", \"id:rdio-CZ\", \"id:rdio-CO\", \"id:rdio-PL\", \"id:rdio-MY\", \"id:rdio-HK\", \"id:rdio-CL\", \"id:twitter_numeric\", \"id:7digital-ES\", or \"id:<CATALOG ID>\""}}}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: echowrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Case
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- spec/fixtures/artist/video.json
|
183
183
|
- spec/fixtures/billie_jean_fingerprint.txt
|
184
184
|
- spec/fixtures/billie_jean_query.json
|
185
|
+
- spec/fixtures/error_response.json
|
185
186
|
- spec/fixtures/oauth/timestamp.json
|
186
187
|
- spec/fixtures/playlist/basic.json
|
187
188
|
- spec/fixtures/playlist/dynamic/create.json
|
@@ -280,6 +281,7 @@ test_files:
|
|
280
281
|
- spec/fixtures/artist/video.json
|
281
282
|
- spec/fixtures/billie_jean_fingerprint.txt
|
282
283
|
- spec/fixtures/billie_jean_query.json
|
284
|
+
- spec/fixtures/error_response.json
|
283
285
|
- spec/fixtures/oauth/timestamp.json
|
284
286
|
- spec/fixtures/playlist/basic.json
|
285
287
|
- spec/fixtures/playlist/dynamic/create.json
|