braintreehttp 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/braintreehttp.gemspec +1 -1
- data/lib/braintreehttp/errors.rb +1 -1
- data/lib/braintreehttp/http_client.rb +5 -5
- data/lib/braintreehttp.rb +0 -1
- data/spec/braintreehttp/http_client_spec.rb +19 -5
- metadata +2 -3
- data/lib/braintreehttp/injector.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 599e49054f1dc90ce4af2229aba6e6bb6140143e
|
4
|
+
data.tar.gz: d9582efa699f71babf7f411744ca33efb34f2f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0fca1e69a0bf2bac1e6445bfc67d433c8323d8cdeeabe3b08437ec5c3fe1a0ce1225b0f68e98d0e72495c0e63905509f57af407c04a6ca2788994abb686e16
|
7
|
+
data.tar.gz: e1c67247bcf30af276952d34601a868d905b99e25cdcb1725ed6d7f66c95a1d5c08075a0b888cbd55212f153ee73dc510a67826302a8769f06613f1cb8ef5357
|
data/braintreehttp.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = "braintreehttp"
|
5
5
|
s.summary = "BraintreeHttp Client Library"
|
6
6
|
s.description = "Used for generated API clients"
|
7
|
-
s.version = "0.1.
|
7
|
+
s.version = "0.1.3"
|
8
8
|
s.license = "MIT"
|
9
9
|
s.author = "Braintree"
|
10
10
|
s.email = "code@getbraintree.com"
|
data/lib/braintreehttp/errors.rb
CHANGED
@@ -19,8 +19,8 @@ module BraintreeHttp
|
|
19
19
|
"BraintreeHttp-Ruby HTTP/1.1"
|
20
20
|
end
|
21
21
|
|
22
|
-
def add_injector(
|
23
|
-
@injectors <<
|
22
|
+
def add_injector(&block)
|
23
|
+
@injectors << block
|
24
24
|
end
|
25
25
|
|
26
26
|
def has_body(request)
|
@@ -33,7 +33,7 @@ module BraintreeHttp
|
|
33
33
|
end
|
34
34
|
|
35
35
|
@injectors.each do |injector|
|
36
|
-
injector.
|
36
|
+
injector.call(request)
|
37
37
|
end
|
38
38
|
|
39
39
|
if !request.headers["User-Agent"] || request.headers["User-Agent"] == "Ruby"
|
@@ -109,7 +109,7 @@ module BraintreeHttp
|
|
109
109
|
headers = response.to_hash
|
110
110
|
if result && !result.empty?
|
111
111
|
deserialized = deserialize_response(response.body, headers)
|
112
|
-
if deserialized.is_a?
|
112
|
+
if deserialized.is_a?(String) || deserialized.is_a?(Array)
|
113
113
|
result = deserialized
|
114
114
|
else
|
115
115
|
result = OpenStruct.new(deserialized)
|
@@ -127,7 +127,7 @@ module BraintreeHttp
|
|
127
127
|
if status_code >= 200 and status_code < 300
|
128
128
|
return obj
|
129
129
|
elsif
|
130
|
-
raise
|
130
|
+
raise HttpError.new(obj.status_code, obj.result, obj.headers)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
data/lib/braintreehttp.rb
CHANGED
@@ -13,13 +13,10 @@ describe HttpClient do
|
|
13
13
|
|
14
14
|
http_client = HttpClient.new(@environment)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
request.headers["Some-Key"] = "Some Value"
|
19
|
-
end
|
16
|
+
http_client.add_injector do |request|
|
17
|
+
request.headers["Some-Key"] = "Some Value"
|
20
18
|
end
|
21
19
|
|
22
|
-
http_client.add_injector(CustomInjector.new)
|
23
20
|
req = OpenStruct.new({:verb => "GET", :path => "/"})
|
24
21
|
|
25
22
|
stub_request(:any, @environment.base_url)
|
@@ -190,6 +187,23 @@ describe HttpClient do
|
|
190
187
|
expect(resp.result).to eq('something else')
|
191
188
|
end
|
192
189
|
|
190
|
+
it 'handles json array result' do
|
191
|
+
WebMock.enable!
|
192
|
+
|
193
|
+
return_data = ["one", "two"]
|
194
|
+
|
195
|
+
http_client = HttpClient.new(@environment)
|
196
|
+
|
197
|
+
stub_request(:get, @environment.base_url + "/v1/api")
|
198
|
+
.to_return(body: JSON.generate(return_data), status: 200, headers: {"Content-Type" => "application/json"})
|
199
|
+
|
200
|
+
req = OpenStruct.new({:verb => "GET", :path => "/v1/api"})
|
201
|
+
|
202
|
+
resp = http_client.execute(req)
|
203
|
+
|
204
|
+
expect(resp.result).to eq(return_data)
|
205
|
+
end
|
206
|
+
|
193
207
|
it "encodes multipart/form-data when a file is present without body" do
|
194
208
|
WebMock.enable!
|
195
209
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braintreehttp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braintree
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Used for generated API clients
|
14
14
|
email: code@getbraintree.com
|
@@ -22,7 +22,6 @@ files:
|
|
22
22
|
- lib/braintreehttp/environment.rb
|
23
23
|
- lib/braintreehttp/errors.rb
|
24
24
|
- lib/braintreehttp/http_client.rb
|
25
|
-
- lib/braintreehttp/injector.rb
|
26
25
|
- spec/braintreehttp/encoder_spec.rb
|
27
26
|
- spec/braintreehttp/http_client_spec.rb
|
28
27
|
- spec/spec_helper.rb
|