braintreehttp 0.4.1 → 0.4.2

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: 2c99359ae4e377913031bf9cc0d7994ba25c4796
4
- data.tar.gz: 44d2ba9c9eed08b368a1d4184c6d657c43169a07
3
+ metadata.gz: 2fa75403a81c2d46f560fce1c8f5f9efc9ef1a23
4
+ data.tar.gz: 502225377013d459e3b5d69f80cc6bf9e4a736a9
5
5
  SHA512:
6
- metadata.gz: 67a093d004f1693645d53e3264ef3f284dbd3af9f3d798f0332d8c3e28aa36318df5094d0d2e959cb1276633f313c3460dcc4608b677b8d52ed0018813b684ad
7
- data.tar.gz: 1550bb9feb4242299c68fea2c06a63c0975f027af3262562c90e7347d0e0a710ff47bc83babfe051e4383cc6dff2f3fbb5c11932aba3cfc08a40999d43773d3e
6
+ metadata.gz: 6679061c1c261486202c71b445c57c95faf6e968dc9670cb6daf949d9d17458c75785dbee32991d391437d5aa97b851d37ffde7c933b4dd2f1b165232c6ca6c7
7
+ data.tar.gz: 9e655d70620e4841e70ba9aafea0cd1efb8870370f6e72c9ab3084210aa08ff504647e7fbe67bea5e28456aab169a20ce8c0fbf255ea58ab192f66b49adcec69
@@ -71,7 +71,7 @@ module BraintreeHttp
71
71
  if deserialized.is_a?(String) || deserialized.is_a?(Array)
72
72
  result = deserialized
73
73
  else
74
- result = OpenStruct.new(deserialized)
74
+ result = _parse_hash(deserialized)
75
75
  end
76
76
  else
77
77
  result = nil
@@ -89,5 +89,19 @@ module BraintreeHttp
89
89
  raise HttpError.new(obj.status_code, obj.result, obj.headers)
90
90
  end
91
91
  end
92
+
93
+ def _parse_hash(hash)
94
+ obj = OpenStruct.new()
95
+
96
+ hash.each do |k, v|
97
+ if v.is_a?(Hash)
98
+ obj[k] = _parse_hash(v)
99
+ else
100
+ obj[k] = v
101
+ end
102
+ end
103
+
104
+ obj
105
+ end
92
106
  end
93
107
  end
@@ -1 +1 @@
1
- VERSION = "0.4.1"
1
+ VERSION = "0.4.2"
@@ -167,7 +167,9 @@ describe Encoder do
167
167
  headers = {"content-type" => ["application/json; charset=utf8"]}
168
168
  body = '{"string":"value","number":1.23,"bool":true,"array":["one","two","three"],"nested":{"nested_string":"nested_value","nested_array":[1,2,3]}}'
169
169
 
170
- expect(Encoder.new.deserialize_response(body, headers)).to eq(expected)
170
+ deserialized = Encoder.new.deserialize_response(body, headers)
171
+
172
+ expect(deserialized).to eq(expected)
171
173
  end
172
174
 
173
175
  it 'deserializes the response when content-type == text/*' do
@@ -105,7 +105,7 @@ describe HttpClient do
105
105
  stub_request(:delete, @environment.base_url + "/path")
106
106
 
107
107
  req = OpenStruct.new({
108
- :verb => "DELETE",
108
+ :verb => "DELETE",
109
109
  :path => "/path",
110
110
  :headers => {
111
111
  "Content-Type" => "text/plain"
@@ -226,6 +226,35 @@ describe HttpClient do
226
226
  expect(resp.result).to eq(return_data)
227
227
  end
228
228
 
229
+ it 'deserializes nested response object into nested openstruct response' do
230
+ WebMock.enable!
231
+
232
+ return_data = {
233
+ :key => 'value',
234
+ :nested_key => {
235
+ :string => 'stringvalue',
236
+ :some_hash => {
237
+ :some_int => 1
238
+ },
239
+ :some_array => [1, 2, 3]
240
+ }
241
+ }
242
+
243
+ http_client = HttpClient.new(@environment)
244
+
245
+ stub_request(:get, @environment.base_url + "/v1/api")
246
+ .to_return(body: JSON.generate(return_data), status: 200, headers: {"Content-Type" => "application/json"})
247
+
248
+ req = OpenStruct.new({:verb => "GET", :path => "/v1/api"})
249
+
250
+ resp = http_client.execute(req)
251
+
252
+ expect(resp.result.key).to eq('value')
253
+ expect(resp.result.nested_key.string).to eq('stringvalue')
254
+ expect(resp.result.nested_key.some_hash.some_int).to eq(1)
255
+ expect(resp.result.nested_key.some_array).to eq([1, 2, 3])
256
+ end
257
+
229
258
  it "does not error if no file or body present on a request class" do
230
259
  class Request
231
260
 
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braintree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-18 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Used for generated API clients
14
14
  email: code@getbraintree.com
@@ -16,8 +16,6 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - braintreehttp.gemspec
20
- - lib/braintreehttp.rb
21
19
  - lib/braintreehttp/encoder.rb
22
20
  - lib/braintreehttp/environment.rb
23
21
  - lib/braintreehttp/errors.rb
@@ -27,9 +25,11 @@ files:
27
25
  - lib/braintreehttp/serializers/multipart.rb
28
26
  - lib/braintreehttp/serializers/text.rb
29
27
  - lib/braintreehttp/version.rb
28
+ - lib/braintreehttp.rb
30
29
  - spec/braintreehttp/encoder_spec.rb
31
30
  - spec/braintreehttp/http_client_spec.rb
32
31
  - spec/spec_helper.rb
32
+ - braintreehttp.gemspec
33
33
  homepage: http://www.braintreepayments.com/
34
34
  licenses:
35
35
  - MIT
@@ -40,17 +40,17 @@ require_paths:
40
40
  - lib
41
41
  required_ruby_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ">="
43
+ - - '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ">="
48
+ - - '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project: braintreehttp
53
- rubygems_version: 2.5.2
53
+ rubygems_version: 2.0.14.1
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: BraintreeHttp Client Library