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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1895d2c71835653fc56bb8c44efab4651ebf32a
4
- data.tar.gz: 4af18f05b407730beb152f2c424d62e13bcea989
3
+ metadata.gz: 599e49054f1dc90ce4af2229aba6e6bb6140143e
4
+ data.tar.gz: d9582efa699f71babf7f411744ca33efb34f2f46
5
5
  SHA512:
6
- metadata.gz: 2683781ee86d293c2eb2bef08ae7e3911f0c72f6f1bb640e115755030a06f23e25c3784426190d4d3398e4cbbf86d997a661f43a5a9f2bfcf83a282e59b92774
7
- data.tar.gz: c7fce1281552eff1c106aa421d599abc5cafbdbeb62a59a6a2660e5ee2f13928c702ada3161ecaf4a18b832ce82751f4a5b82f5e93eb17b317ae769ed1a21224
6
+ metadata.gz: 2e0fca1e69a0bf2bac1e6445bfc67d433c8323d8cdeeabe3b08437ec5c3fe1a0ce1225b0f68e98d0e72495c0e63905509f57af407c04a6ca2788994abb686e16
7
+ data.tar.gz: e1c67247bcf30af276952d34601a868d905b99e25cdcb1725ed6d7f66c95a1d5c08075a0b888cbd55212f153ee73dc510a67826302a8769f06613f1cb8ef5357
@@ -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.2"
7
+ s.version = "0.1.3"
8
8
  s.license = "MIT"
9
9
  s.author = "Braintree"
10
10
  s.email = "code@getbraintree.com"
@@ -1,5 +1,5 @@
1
1
  module BraintreeHttp
2
- class ServiceIOError < IOError
2
+ class HttpError < IOError
3
3
  attr_accessor :status_code, :result, :headers
4
4
  def initialize(status_code, result, headers)
5
5
  @status_code = status_code
@@ -19,8 +19,8 @@ module BraintreeHttp
19
19
  "BraintreeHttp-Ruby HTTP/1.1"
20
20
  end
21
21
 
22
- def add_injector(inj)
23
- @injectors << inj
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.inject(request)
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? String
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 ServiceIOError.new(obj.status_code, obj.result, obj.headers)
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
@@ -1,6 +1,5 @@
1
1
  module BraintreeHttp
2
2
  require_relative "braintreehttp/environment"
3
- require_relative "braintreehttp/injector"
4
3
  require_relative "braintreehttp/http_client"
5
4
  require_relative "braintreehttp/errors"
6
5
  require_relative "braintreehttp/encoder"
@@ -13,13 +13,10 @@ describe HttpClient do
13
13
 
14
14
  http_client = HttpClient.new(@environment)
15
15
 
16
- class CustomInjector < Injector
17
- def inject(request)
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.2
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-10 00:00:00.000000000 Z
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
@@ -1,7 +0,0 @@
1
- module BraintreeHttp
2
- class Injector
3
- def inject(request)
4
- raise NotImplementedError, "Injectors must implement inject"
5
- end
6
- end
7
- end