paypalhttp 1.0.0 → 2.0.1

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
  SHA256:
3
- metadata.gz: 6e1d7486774ce1d1a9a52d214a00f3212196d0d1da58b599861056a0367753db
4
- data.tar.gz: 18f0971f48707107899ed7cbd397384605b334e761ef33176c9b642742e8bf31
3
+ metadata.gz: e7b784f809b45daa88b7b605a078233f9d6d6389de4d22c58810ad904b1e6270
4
+ data.tar.gz: 83f24bf689519c48fb95474ffca65635b2c27eacecbabc4e4194761f88e2bceb
5
5
  SHA512:
6
- metadata.gz: 219e4ffe88eeabfde09731075a2dfd92394568c14d64c0ac4d6f9ac2d2cfe7e24e36353150555fe922077b761e5b01678ae1d3df0435cb10a377bae99d223870
7
- data.tar.gz: ed6ee01c152150c9df2d34b47cb1f620271e549c1f8e8953cdbc19eded34d83c7604c97ca6929db8ab9feb972ea03d8221c62758151a615de65b73ac915171e0
6
+ metadata.gz: f6ccd5a75ac2a07ef84c2cc55d4caacd529bd075315ec040066b1c5cdd625d5de048e11b483318eb7adc3065ceec1ac9d3aed568df4dbc1cba30bf390749cafb
7
+ data.tar.gz: cebe0720259ce83416259eed470253ba5ec716eb329216617fd79a4eabf16a576a4e5c54a9b967852c3a0009fe478a37910aacfff333bdf75b41fa2acdc1113e
@@ -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
@@ -2,10 +2,14 @@ require 'uri'
2
2
 
3
3
  module PayPalHttp
4
4
  class FormEncoded
5
+ def initialize
6
+ @parser = URI::Parser.new()
7
+ end
8
+
5
9
  def encode(request)
6
10
  encoded_params = []
7
11
  request.body.each do |k, v|
8
- encoded_params.push("#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}")
12
+ encoded_params.push("#{@parser.escape(k.to_s)}=#{@parser.escape(v.to_s)}")
9
13
  end
10
14
 
11
15
  encoded_params.join("&")
@@ -1 +1 @@
1
- VERSION = "1.0.0"
1
+ VERSION = "2.0.1"
@@ -108,6 +108,39 @@ describe Encoder do
108
108
  expect(serialized).to eq("key=value%20with%20a%20space&another_key=1013")
109
109
  end
110
110
 
111
+ it 'encodes different special/unsafe characters when using a URI parser' do
112
+ req = OpenStruct.new({
113
+ :verb => "POST",
114
+ :path => "/v1/api",
115
+ :headers => {
116
+ "content-type" => "application/x-www-form-urlencoded; charset=utf8"
117
+ },
118
+ :body => {
119
+ :key => " ..<..>..%..{..}..|..^..`..!",
120
+ :another_key => 1013,
121
+ }
122
+ })
123
+ serialized = Encoder.new.serialize_request(req)
124
+
125
+ expect(serialized).to eq("key=%20..%3C..%3E..%25..%7B..%7D..%7C..%5E..%60..!&another_key=1013")
126
+ end
127
+
128
+ it 'does not encode links given certain special characters' do
129
+ req = OpenStruct.new({
130
+ :verb => "POST",
131
+ :path => "/v1/api",
132
+ :headers => {
133
+ "content-type" => "application/x-www-form-urlencoded; charset=utf8"
134
+ },
135
+ :body => {
136
+ :key => "https://localhost:3001/"
137
+ }
138
+ })
139
+ serialized = Encoder.new.serialize_request(req)
140
+
141
+ expect(serialized).to eq("key=https://localhost:3001/")
142
+ end
143
+
111
144
  it 'throws when content-type is unsupported' do
112
145
  req = OpenStruct.new({
113
146
  :headers => {
@@ -205,6 +238,26 @@ describe Encoder do
205
238
  expect(deserialized).to eq(expected)
206
239
  end
207
240
 
241
+ it 'deserializes the response when content-type == application/json: case insensitive' do
242
+ expected = {
243
+ "string" => "value",
244
+ "number" => 1.23,
245
+ "bool" => true,
246
+ "array" => ["one", "two", "three"],
247
+ "nested" => {
248
+ "nested_string" => "nested_value",
249
+ "nested_array" => [1,2,3]
250
+ }
251
+ }
252
+
253
+ headers = {"content-type" => ["application/JSON; charset=utf8"]}
254
+ body = '{"string":"value","number":1.23,"bool":true,"array":["one","two","three"],"nested":{"nested_string":"nested_value","nested_array":[1,2,3]}}'
255
+
256
+ deserialized = Encoder.new.deserialize_response(body, headers)
257
+
258
+ expect(deserialized).to eq(expected)
259
+ end
260
+
208
261
  it 'deserializes the response when content-type == text/*' do
209
262
  headers = {"content-type" => ["text/plain; charset=utf8"]}
210
263
  body = 'some text'
@@ -212,6 +265,13 @@ describe Encoder do
212
265
  expect(Encoder.new.deserialize_response(body, headers)).to eq('some text')
213
266
  end
214
267
 
268
+ it 'deserializes the response when content-type == text/*: case insensitive' do
269
+ headers = {"content-type" => ["TEXT/plain; charset=utf8"]}
270
+ body = 'some text'
271
+
272
+ expect(Encoder.new.deserialize_response(body, headers)).to eq('some text')
273
+ end
274
+
215
275
  it 'throws when attempting to deserialize multipart/*' do
216
276
  headers = {"content-type" => ["multipart/form-data"]}
217
277
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypalhttp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayPal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Used for generated API clients
14
14
  email:
@@ -52,7 +52,7 @@ 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
55
+ rubygems_version: 3.0.3.1
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: PayPalHttp Client Library