paypalhttp 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e1d7486774ce1d1a9a52d214a00f3212196d0d1da58b599861056a0367753db
4
- data.tar.gz: 18f0971f48707107899ed7cbd397384605b334e761ef33176c9b642742e8bf31
3
+ metadata.gz: 21343a9b1bd5b019013244665c45fa5a88eb32d6e4735e92ae4d0f61a8902d61
4
+ data.tar.gz: 7372fafb251adf5c7571dfa9659f161742de0afdcd2eb822cdd10a1525fd3430
5
5
  SHA512:
6
- metadata.gz: 219e4ffe88eeabfde09731075a2dfd92394568c14d64c0ac4d6f9ac2d2cfe7e24e36353150555fe922077b761e5b01678ae1d3df0435cb10a377bae99d223870
7
- data.tar.gz: ed6ee01c152150c9df2d34b47cb1f620271e549c1f8e8953cdbc19eded34d83c7604c97ca6929db8ab9feb972ea03d8221c62758151a615de65b73ac915171e0
6
+ metadata.gz: ad0f5323b3da8d9650d0fc2d41a68050e80cefd9b37e0a84b0a021c015b40c647aeb127f62291189b1e25d0c104ed9ba495b112435aa087cbad5089548481f35
7
+ data.tar.gz: d5930250391a51720f17a275e0ba4151389194c095b0381ee2d705c1f6d42003a2d6733ce049f540668662b8a6890584c69fa23f15d8b2d387aca9537bad9429
@@ -41,6 +41,7 @@ module PayPalHttp
41
41
  raise UnsupportedEncodingError.new('HttpResponse did not have Content-Type header set') unless headers && (headers['content-type'])
42
42
 
43
43
  content_type = _extract_header(headers, 'content-type')
44
+ content_type.downcase!
44
45
 
45
46
  enc = _encoder(content_type)
46
47
  raise UnsupportedEncodingError.new("Unable to deserialize response with Content-Type #{content_type}. Supported decodings are #{supported_encodings}") unless enc
@@ -28,7 +28,13 @@ module PayPalHttp
28
28
  def format_headers(headers)
29
29
  formatted_headers = {}
30
30
  headers.each do |key, value|
31
- formatted_headers[key.downcase] = value
31
+ # TODO: Since header is treated as a hash, val is in an array.
32
+ # Will this cause an issue when accessing and modifying val
33
+ # Ensure this is the case and will not propegate access issues/errors
34
+ if key.casecmp("content-type") == 0
35
+ value[0].downcase!
36
+ end
37
+ formatted_headers[key.downcase] = value
32
38
  end
33
39
  formatted_headers
34
40
  end
@@ -1 +1 @@
1
- VERSION = "1.0.0"
1
+ VERSION = "1.0.1"
@@ -205,6 +205,26 @@ describe Encoder do
205
205
  expect(deserialized).to eq(expected)
206
206
  end
207
207
 
208
+ it 'deserializes the response when content-type == application/json: case insensitive' do
209
+ expected = {
210
+ "string" => "value",
211
+ "number" => 1.23,
212
+ "bool" => true,
213
+ "array" => ["one", "two", "three"],
214
+ "nested" => {
215
+ "nested_string" => "nested_value",
216
+ "nested_array" => [1,2,3]
217
+ }
218
+ }
219
+
220
+ headers = {"content-type" => ["application/JSON; charset=utf8"]}
221
+ body = '{"string":"value","number":1.23,"bool":true,"array":["one","two","three"],"nested":{"nested_string":"nested_value","nested_array":[1,2,3]}}'
222
+
223
+ deserialized = Encoder.new.deserialize_response(body, headers)
224
+
225
+ expect(deserialized).to eq(expected)
226
+ end
227
+
208
228
  it 'deserializes the response when content-type == text/*' do
209
229
  headers = {"content-type" => ["text/plain; charset=utf8"]}
210
230
  body = 'some text'
@@ -212,6 +232,13 @@ describe Encoder do
212
232
  expect(Encoder.new.deserialize_response(body, headers)).to eq('some text')
213
233
  end
214
234
 
235
+ it 'deserializes the response when content-type == text/*: case insensitive' do
236
+ headers = {"content-type" => ["TEXT/plain; charset=utf8"]}
237
+ body = 'some text'
238
+
239
+ expect(Encoder.new.deserialize_response(body, headers)).to eq('some text')
240
+ end
241
+
215
242
  it 'throws when attempting to deserialize multipart/*' do
216
243
  headers = {"content-type" => ["multipart/form-data"]}
217
244
  body = 'some multipart encoded data here'
@@ -226,6 +226,57 @@ describe HttpClient do
226
226
  expect(resp.result).to eq(return_data)
227
227
  end
228
228
 
229
+ it 'handles json array result: case insensitive' do
230
+ WebMock.enable!
231
+
232
+ return_data = ["one", "two"]
233
+
234
+ http_client = HttpClient.new(@environment)
235
+
236
+ stub_request(:get, @environment.base_url + "/v1/api")
237
+ .to_return(body: JSON.generate(return_data), status: 200, headers: {"Content-Type" => "application/JSON"})
238
+
239
+ req = OpenStruct.new({:verb => "GET", :path => "/v1/api"})
240
+
241
+ resp = http_client.execute(req)
242
+
243
+ expect(resp.result).to eq(return_data)
244
+ end
245
+
246
+ it 'handles plain text result' do
247
+ WebMock.enable!
248
+
249
+ return_data = "value"
250
+
251
+ http_client = HttpClient.new(@environment)
252
+
253
+ stub_request(:get, @environment.base_url + "/v1/api")
254
+ .to_return(body: return_data, status: 200, headers: {"Content-Type" => "text/plain; charset=utf8"})
255
+
256
+ req = OpenStruct.new({:verb => "GET", :path => "/v1/api"})
257
+
258
+ resp = http_client.execute(req)
259
+
260
+ expect(resp.result).to eq(return_data)
261
+ end
262
+
263
+ it 'handles plain text result: case insensitive' do
264
+ WebMock.enable!
265
+
266
+ return_data = "value"
267
+
268
+ http_client = HttpClient.new(@environment)
269
+
270
+ stub_request(:get, @environment.base_url + "/v1/api")
271
+ .to_return(body: return_data, status: 200, headers: {"Content-Type" => "TEXT/plain; charset=utf8"})
272
+
273
+ req = OpenStruct.new({:verb => "GET", :path => "/v1/api"})
274
+
275
+ resp = http_client.execute(req)
276
+
277
+ expect(resp.result).to eq(return_data)
278
+ end
279
+
229
280
  it 'deserializes nested response object into nested openstruct response' do
230
281
  WebMock.enable!
231
282
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypalhttp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayPal
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Used for generated API clients
14
- email:
14
+ email:
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
@@ -33,11 +33,11 @@ files:
33
33
  - spec/paypalhttp/serializers/form_part_spec.rb
34
34
  - spec/paypalhttp/serializers/multipart_spec.rb
35
35
  - spec/spec_helper.rb
36
- homepage:
36
+ homepage:
37
37
  licenses:
38
38
  - MIT
39
39
  metadata: {}
40
- post_install_message:
40
+ post_install_message:
41
41
  rdoc_options: []
42
42
  require_paths:
43
43
  - lib
@@ -52,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.0.3
56
- signing_key:
55
+ rubygems_version: 3.0.9
56
+ signing_key:
57
57
  specification_version: 4
58
58
  summary: PayPalHttp Client Library
59
59
  test_files: []