connect-sdk-ruby 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/connect-sdk-ruby.gemspec +2 -2
- data/lib/ingenico/connect/sdk/defaultimpl/default_authenticator.rb +9 -10
- data/lib/ingenico/connect/sdk/defaultimpl/default_connection.rb +13 -14
- data/lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb +6 -5
- data/lib/ingenico/connect/sdk/domain/product/payment_product.rb +7 -0
- data/lib/ingenico/connect/sdk/logging/communicator_logger.rb +2 -2
- data/lib/ingenico/connect/sdk/logging/log_message_builder.rb +2 -1
- data/lib/ingenico/connect/sdk/logging/logging_capable.rb +12 -12
- data/lib/ingenico/connect/sdk/logging/logging_util.rb +17 -15
- data/lib/ingenico/connect/sdk/logging/request_log_message_builder.rb +2 -1
- data/lib/ingenico/connect/sdk/logging/ruby_communicator_logger.rb +5 -5
- data/lib/ingenico/connect/sdk/logging/stdout_communicator_logger.rb +6 -8
- data/lib/ingenico/connect/sdk/meta_data_provider.rb +1 -1
- data/lib/ingenico/connect/sdk/request_header.rb +1 -1
- data/lib/ingenico/connect/sdk/request_param.rb +1 -1
- data/lib/ingenico/connect/sdk/response.rb +20 -23
- data/lib/ingenico/connect/sdk/response_header.rb +2 -4
- data/spec/lib/defaultimpl/default_connection_spec.rb +4 -10
- data/spec/lib/logging/value_obfuscator_spec.rb +14 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 382c89312291bda76c2d9ef5a8503566ab9b907c
|
4
|
+
data.tar.gz: 59dc66a56515e7d69eb9d9ce8d74be8d85d8df68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d45bc44bff3aa14d2c0a80a53f224daac190cd739a70e1ffcc048fd19e63e3dc45ab938190f84b34029bcc5a3c2a0670f955b3a21a779270e3a6ecea6bb9c9c8
|
7
|
+
data.tar.gz: c75aa39e5ad2e80a7ca972f25d765e853597ec67f89c6fca85942205a73c2a144d6e1cc6ff1869b0db2c83bed6cbe1fac6dfba8b3f6dc8b5210b998285ecdbd9
|
data/README.md
CHANGED
@@ -28,6 +28,7 @@ Note that the source code of the unit tests, integration tests and the examples
|
|
28
28
|
## Requirements
|
29
29
|
|
30
30
|
Ruby 2.2 and higher versions are required. Ruby 2.1.10 is also supported but is not suggested because official support has ended and security maintenance will end soon.
|
31
|
+
As for JRuby, version 9.0.0.0 and higher are supported.
|
31
32
|
In addition, the following package is required:
|
32
33
|
|
33
34
|
* [httpclient](https://github.com/nahi/httpclient) 2.8 or higher
|
@@ -76,7 +77,7 @@ After the Ruby SDK has been installed, it can be required in Ruby program as fol
|
|
76
77
|
|
77
78
|
require 'ingenico/connect/sdk'
|
78
79
|
|
79
|
-
## Running tests
|
80
|
+
## Running tests
|
80
81
|
|
81
82
|
There are two types of tests: unit tests and integration tests. The unit tests will work out-of-the-box; for the integration tests some configuration is required.
|
82
83
|
First, some environment variables need to be set:
|
data/connect-sdk-ruby.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'connect-sdk-ruby'
|
3
|
-
spec.version = '1.
|
3
|
+
spec.version = '1.2.0'
|
4
4
|
spec.authors = ['Ingenico ePayments']
|
5
5
|
spec.email = ['github@epay.ingenico.com']
|
6
6
|
spec.summary = %q{SDK to communicate with the GlobalCollect platform using the Ingenico Connect Server API}
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)\/})
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
|
-
spec.required_ruby_version = '
|
18
|
+
spec.required_ruby_version = '>= 2.0'
|
19
19
|
|
20
20
|
spec.add_dependency 'httpclient', '~> 2.8'
|
21
21
|
|
@@ -6,11 +6,12 @@ module Ingenico::Connect::SDK
|
|
6
6
|
|
7
7
|
# Authenticates requests made to the GlobalCollect platform using the HMAC algorithm.
|
8
8
|
class DefaultAuthenticator < Authenticator
|
9
|
+
|
9
10
|
# HMAC algorithm used to generate the signature
|
10
|
-
HMAC_ALGOR = 'SHA256'
|
11
|
-
CONTENT_TYPE = 'Content-Type'
|
12
|
-
DATE = 'Date'
|
13
|
-
XGCS = 'x-gcs'
|
11
|
+
HMAC_ALGOR = 'SHA256'.freeze
|
12
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
13
|
+
DATE = 'Date'.freeze
|
14
|
+
XGCS = 'x-gcs'.freeze
|
14
15
|
|
15
16
|
# Construct a new DefaultAuthenticator instance that can sign requests
|
16
17
|
# with the provided _api_key_id_ and _secret_api_key_.
|
@@ -69,11 +70,9 @@ module Ingenico::Connect::SDK
|
|
69
70
|
|
70
71
|
xgc_http_headers.sort! { |(h1, v1), (h2, v2)| h1 <=> h2 } unless xgc_http_headers.empty?
|
71
72
|
|
72
|
-
data = http_method.upcase
|
73
|
-
|
74
|
-
data
|
75
|
-
data += canonical_resource + "\n" unless canonical_resource.nil?
|
76
|
-
data
|
73
|
+
data = "#{http_method.upcase}\n#{content_type}\n#{date}\n"
|
74
|
+
data << xgc_http_headers.inject('') { |s, (k, v)| "#{s}#{k}:#{v}\n" } unless xgc_http_headers.empty?
|
75
|
+
data << "#{canonical_resource}\n" unless canonical_resource.nil?
|
77
76
|
end
|
78
77
|
|
79
78
|
# Applies the HMAC algorithm to the canonicalized data to obtain an HMAC digest.
|
@@ -88,7 +87,7 @@ module Ingenico::Connect::SDK
|
|
88
87
|
|
89
88
|
# Returns the encoded URI path without the HTTP method and including all decoded query parameters.
|
90
89
|
def to_canonical_resource(resource_uri)
|
91
|
-
return resource_uri.path
|
90
|
+
return "#{resource_uri.path}?#{resource_uri.query}" if resource_uri.query
|
92
91
|
return resource_uri.path
|
93
92
|
end
|
94
93
|
|
@@ -3,21 +3,24 @@ require 'uri'
|
|
3
3
|
require 'httpclient'
|
4
4
|
|
5
5
|
# @private :nodoc: this is not our class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
module RefineHTTPClient
|
7
|
+
refine HTTPClient do
|
8
|
+
# (monkey) patch to gain access to the session pool size in HTTPClient
|
9
|
+
def session_count
|
10
|
+
sess_pool = @session_manager.instance_variable_get(:@sess_pool)
|
11
|
+
sess_pool.size
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
module Ingenico::Connect::SDK
|
15
17
|
module DefaultImpl
|
16
|
-
|
17
18
|
class DefaultConnection < PooledConnection
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
using RefineHTTPClient
|
21
|
+
|
22
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
23
|
+
JSON_CONTENT_TYPE = 'application/json'.freeze
|
21
24
|
|
22
25
|
# Initialized using a hash containing the following parameters:
|
23
26
|
# connect_timeout:: Connection timeout in seconds.
|
@@ -182,16 +185,12 @@ module Ingenico::Connect::SDK
|
|
182
185
|
|
183
186
|
# Converts a {Ingenico::Connect::SDK::RequestHeader} list headers to a hash
|
184
187
|
def convert_from_sdk_headers(headers)
|
185
|
-
hash =
|
186
|
-
headers.each { |h| hash[h.name] = h.value }
|
187
|
-
hash
|
188
|
+
headers.inject({}) { |hash, h| hash[h.name] = h.value ; hash}
|
188
189
|
end
|
189
190
|
|
190
191
|
# Converts a hash to a {Ingenico::Connect::SDK::ResponseHeader} list
|
191
192
|
def convert_to_sdk_headers(headers)
|
192
|
-
arr
|
193
|
-
headers.each { |k, v| arr << Ingenico::Connect::SDK::ResponseHeader.new(k, v) }
|
194
|
-
arr
|
193
|
+
headers.inject([]) { |arr, (k, v)| arr << Ingenico::Connect::SDK::ResponseHeader.new(k, v) }
|
195
194
|
end
|
196
195
|
|
197
196
|
# converts a HTTPClient response to a {Ingenico::Connect::SDK::Response}
|
@@ -1,15 +1,16 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'singleton'
|
2
3
|
|
3
4
|
module Ingenico::Connect::SDK
|
4
5
|
module DefaultImpl
|
5
|
-
|
6
|
-
# Marshals objects to and from JSON format.
|
6
|
+
# marshals objects to and from JSON format.
|
7
7
|
# Currently supports marshalling and unmarshalling of classes that support class.new_from_hash and class#to_h
|
8
8
|
class DefaultMarshaller < Ingenico::Connect::SDK::Marshaller
|
9
|
-
|
9
|
+
include Singleton
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# NOTE: this alias is needed to not break existing method calls depending on old interface
|
12
|
+
class << self
|
13
|
+
alias_method :INSTANCE, :instance
|
13
14
|
end
|
14
15
|
|
15
16
|
# marshals the _request_object_ to a JSON string using request_object#to_h
|
@@ -26,6 +26,9 @@ module Ingenico::Connect::SDK
|
|
26
26
|
# true/false
|
27
27
|
attr_accessor :auto_tokenized
|
28
28
|
|
29
|
+
# true/false
|
30
|
+
attr_accessor :can_be_iframed
|
31
|
+
|
29
32
|
# {Ingenico::Connect::SDK::Domain::Product::PaymentProductDisplayHints}
|
30
33
|
attr_accessor :display_hints
|
31
34
|
|
@@ -59,6 +62,7 @@ module Ingenico::Connect::SDK
|
|
59
62
|
add_to_hash(hash, 'allowsRecurring', @allows_recurring)
|
60
63
|
add_to_hash(hash, 'allowsTokenization', @allows_tokenization)
|
61
64
|
add_to_hash(hash, 'autoTokenized', @auto_tokenized)
|
65
|
+
add_to_hash(hash, 'canBeIframed', @can_be_iframed)
|
62
66
|
add_to_hash(hash, 'displayHints', @display_hints)
|
63
67
|
add_to_hash(hash, 'fields', @fields)
|
64
68
|
add_to_hash(hash, 'id', @id)
|
@@ -91,6 +95,9 @@ module Ingenico::Connect::SDK
|
|
91
95
|
if hash.has_key?('autoTokenized')
|
92
96
|
@auto_tokenized = hash['autoTokenized']
|
93
97
|
end
|
98
|
+
if hash.has_key?('canBeIframed')
|
99
|
+
@can_be_iframed = hash['canBeIframed']
|
100
|
+
end
|
94
101
|
if hash.has_key?('displayHints')
|
95
102
|
if !(hash['displayHints'].is_a? Hash)
|
96
103
|
raise TypeError, "value '%s' is not a Hash" % [hash['displayHints']]
|
@@ -7,12 +7,12 @@ module Ingenico::Connect::SDK
|
|
7
7
|
# @see Ingenico::Connect::SDK::Logging::StdoutCommunicatorLogger
|
8
8
|
# @see Ingenico::Connect::SDK::Logging::RubyCommunicatorLogger
|
9
9
|
def initialize
|
10
|
-
raise NotImplementedError("#{self.class.name} is not implemented.")
|
10
|
+
raise NotImplementedError.new("#{self.class.name} is not implemented.")
|
11
11
|
end
|
12
12
|
|
13
13
|
# logs a message with or without exception
|
14
14
|
def log(message, thrown=false)
|
15
|
-
raise NotImplementedError("#{self.class.name}#log() is not implemented.")
|
15
|
+
raise NotImplementedError.new("#{self.class.name}#log() is not implemented.")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -41,7 +41,7 @@ module Ingenico::Connect::SDK
|
|
41
41
|
|
42
42
|
# Constructs and returns the log message as a string.
|
43
43
|
def get_message
|
44
|
-
raise NotImplementedError("#{self.class.name}#get_message() is not implemented.")
|
44
|
+
raise NotImplementedError.new("#{self.class.name}#get_message() is not implemented.")
|
45
45
|
end
|
46
46
|
|
47
47
|
def to_s
|
@@ -56,6 +56,7 @@ module Ingenico::Connect::SDK
|
|
56
56
|
protected def empty_if_null(value)
|
57
57
|
value.nil? ? '' : value
|
58
58
|
end
|
59
|
+
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Ingenico
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
module Connect
|
3
|
+
module SDK
|
4
|
+
module Logging
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# Abstract mixin module that allows loggers to be registered to an object.
|
7
|
+
module LoggingCapable
|
8
|
+
def enable_logging(communicator_logger)
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
12
|
+
def disable_logging
|
13
|
+
raise NotImplementedError
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,7 +4,16 @@ module Ingenico::Connect::SDK
|
|
4
4
|
# Class responsible for obfuscating sensitive data in a message body.
|
5
5
|
class ValueObfuscator
|
6
6
|
|
7
|
-
|
7
|
+
class << self
|
8
|
+
|
9
|
+
alias_method :private_new, :new
|
10
|
+
|
11
|
+
def new(*args)
|
12
|
+
raise NoMethodError.new('ValueObfuscator should not explicitly instantiated!')
|
13
|
+
end
|
14
|
+
|
15
|
+
private :private_new, :new
|
16
|
+
end
|
8
17
|
|
9
18
|
# Creates a new ValueObfuscator.
|
10
19
|
# fixed_length:: If greater than 0, all values that will be obfuscated
|
@@ -22,27 +31,26 @@ module Ingenico::Connect::SDK
|
|
22
31
|
|
23
32
|
public
|
24
33
|
|
25
|
-
@@ALL = ValueObfuscator.new(0, 0, 0)
|
26
|
-
|
27
34
|
def self.ALL
|
28
|
-
|
35
|
+
# use lazy instantiation
|
36
|
+
@@ALL ||= ValueObfuscator.send(:private_new, 0, 0, 0)
|
29
37
|
end
|
30
38
|
|
31
39
|
# Creates a new ValueObfuscator that replaces any sensitive data with a _fixed_length_ line of asterisks.
|
32
40
|
def self.fixed_length(fixed_length)
|
33
|
-
ValueObfuscator.
|
41
|
+
ValueObfuscator.send(:private_new, fixed_length, 0, 0)
|
34
42
|
end
|
35
43
|
|
36
44
|
# Creates a new ValueObfuscator that retains only the first _count_ characters of any value to obfuscate
|
37
45
|
# and replaces the rest with asterisks.
|
38
46
|
def self.keep_start_count(count)
|
39
|
-
ValueObfuscator.
|
47
|
+
ValueObfuscator.send(:private_new, 0, count, 0)
|
40
48
|
end
|
41
49
|
|
42
50
|
# Creates a new ValueObfuscator that retains only the last _count_ characters of any value to obfuscate
|
43
51
|
# and replaces the rest with asterisks.
|
44
52
|
def self.keep_end_count(count)
|
45
|
-
ValueObfuscator.
|
53
|
+
ValueObfuscator.send(:private_new, 0, 0, count)
|
46
54
|
end
|
47
55
|
|
48
56
|
# Obfuscates the parameter value.
|
@@ -168,9 +176,6 @@ module Ingenico::Connect::SDK
|
|
168
176
|
super(name, fixedLength)
|
169
177
|
end
|
170
178
|
|
171
|
-
# with_keep_start_count and with_keep_end_count are the same
|
172
|
-
# no need to override
|
173
|
-
|
174
179
|
def build
|
175
180
|
HeaderObfuscator.new(obfuscators)
|
176
181
|
end
|
@@ -200,7 +205,7 @@ module Ingenico::Connect::SDK
|
|
200
205
|
# The negative lookbehind is to allow escaped quotes to be part of
|
201
206
|
# the value. What this does not allow currently is having values end
|
202
207
|
# with a \ (which would be escaped to \\).
|
203
|
-
regex = pn.inject("([\"'])(") { |r, p| r
|
208
|
+
regex = pn.inject("([\"'])(") { |r, p| "#{r}#{Regexp.quote(p)}|"}.chop <<
|
204
209
|
")\\1\\s*:\\s*(?:([\"'])(.*?)(?<!\\\\)\\3|([^\"'\\s]\\S*))"
|
205
210
|
/#{regex}/m # dotall mode
|
206
211
|
end
|
@@ -226,7 +231,6 @@ module Ingenico::Connect::SDK
|
|
226
231
|
|
227
232
|
class Builder < Obfuscator::Builder
|
228
233
|
def initialize
|
229
|
-
# implement the class
|
230
234
|
@obfuscators = {}
|
231
235
|
end
|
232
236
|
|
@@ -256,7 +260,7 @@ module Ingenico::Connect::SDK
|
|
256
260
|
end
|
257
261
|
end # end of property obfuscator
|
258
262
|
|
259
|
-
|
263
|
+
module LoggingUtil
|
260
264
|
@@PROPERTY_OBFUSCATOR = PropertyObfuscator.builder
|
261
265
|
.with_keep_end_count("cardNumber", 4)
|
262
266
|
.with_keep_end_count("expiryDate", 2)
|
@@ -284,8 +288,6 @@ module Ingenico::Connect::SDK
|
|
284
288
|
.with_fixed_length("X-GCS-CallerPassword", 8)
|
285
289
|
.build
|
286
290
|
|
287
|
-
private_class_method :new
|
288
|
-
|
289
291
|
def self.obfuscate_body(body)
|
290
292
|
@@PROPERTY_OBFUSCATOR.obfuscate(body)
|
291
293
|
end
|
@@ -33,10 +33,11 @@ module Ingenico::Connect::SDK
|
|
33
33
|
if @uri.query.nil?
|
34
34
|
return @uri.path
|
35
35
|
else
|
36
|
-
return @uri.path
|
36
|
+
return "#{@uri.path}?#{@uri.query}" unless @uri.query.nil?
|
37
37
|
end
|
38
38
|
# @uri.path + '?' + empty_if_null(@uri.query)
|
39
39
|
end
|
40
|
+
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -36,11 +36,11 @@ module Ingenico::Connect::SDK
|
|
36
36
|
# Opens or creates a new file in write-only mode with _filename_.
|
37
37
|
def self.create_logfile(filename)
|
38
38
|
logdev = begin
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL))
|
40
|
+
rescue Errno::EEXIST
|
41
|
+
# file is created by another process
|
42
|
+
open_logfile(filename)
|
43
|
+
end
|
44
44
|
logdev.sync = true
|
45
45
|
logdev
|
46
46
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'English'
|
2
|
+
require 'singleton'
|
2
3
|
|
3
4
|
module Ingenico::Connect::SDK
|
4
5
|
module Logging
|
@@ -6,18 +7,15 @@ module Ingenico::Connect::SDK
|
|
6
7
|
# {Ingenico::Connect::SDK::Logging::CommunicatorLogger} that logs the messages to $stdout.
|
7
8
|
class StdoutCommunicatorLogger < CommunicatorLogger
|
8
9
|
|
10
|
+
include Singleton
|
11
|
+
|
9
12
|
def initialize
|
10
13
|
# implement the interface
|
11
14
|
end
|
12
15
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
private_class_method :new
|
17
|
-
|
18
|
-
# Returns the StdoutCommunicatorLogger instance
|
19
|
-
def self.INSTANCE
|
20
|
-
@@INSTANCE
|
16
|
+
# NOTE: this is needed to not break method calls based on old interface
|
17
|
+
class << self
|
18
|
+
alias_method :INSTANCE, :instance
|
21
19
|
end
|
22
20
|
|
23
21
|
# Logs a single error or non-error message to $stdout.
|
@@ -5,7 +5,7 @@ module Ingenico::Connect::SDK
|
|
5
5
|
|
6
6
|
# Manages metadata about the server using the SDK
|
7
7
|
class MetaDataProvider
|
8
|
-
@@SDK_VERSION = '1.
|
8
|
+
@@SDK_VERSION = '1.2.0'
|
9
9
|
@@SERVER_META_INFO_HEADER = 'X-GCS-ServerMetaInfo'
|
10
10
|
@@PROHIBITED_HEADERS = [@@SERVER_META_INFO_HEADER, 'X-GCS-Idempotence-Key',
|
11
11
|
'Date', 'Content-Type', 'Authorization'].sort!.freeze
|
@@ -10,36 +10,38 @@ module Ingenico::Connect::SDK
|
|
10
10
|
def initialize(status_code, body, headers)
|
11
11
|
@status_code = status_code
|
12
12
|
@body = body
|
13
|
-
if headers.nil?
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
@headers = if headers.nil? or headers.empty?
|
14
|
+
{}
|
15
|
+
else
|
16
|
+
headers.inject({}) do |hash, header|
|
17
|
+
hash[header.name.downcase.to_sym] = header.dup.freeze
|
18
|
+
hash
|
19
|
+
end
|
20
|
+
end.freeze
|
18
21
|
end
|
19
22
|
|
20
23
|
# HTTP status code
|
21
24
|
attr_reader :status_code
|
25
|
+
|
22
26
|
# Response message body
|
23
27
|
attr_reader :body
|
28
|
+
|
24
29
|
# Response headers as a {Ingenico::Connect::SDK::ResponseHeader} list
|
25
|
-
|
30
|
+
def headers
|
31
|
+
@headers.values
|
32
|
+
end
|
26
33
|
|
27
34
|
# Returns the {Ingenico::Connect::SDK::ResponseHeader} that goes by the given _header_name_,
|
28
35
|
# or _nil_ if this Response does not contain a header with the given name.
|
29
36
|
def get_header(header_name)
|
30
|
-
@headers.
|
31
|
-
if header.name.casecmp(header_name) == 0
|
32
|
-
return header
|
33
|
-
end
|
34
|
-
}
|
35
|
-
return nil
|
37
|
+
@headers[header_name.downcase.to_sym]
|
36
38
|
end
|
37
39
|
|
38
40
|
# Returns the header value of the header that goes by the given _header_name_,
|
39
41
|
# or _nil_ if this Response does not contain a header with the given name.
|
40
42
|
def get_header_value(header_name)
|
41
43
|
header = get_header(header_name)
|
42
|
-
|
44
|
+
unless header.nil?
|
43
45
|
header.value
|
44
46
|
else
|
45
47
|
nil
|
@@ -47,16 +49,11 @@ module Ingenico::Connect::SDK
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def to_s
|
50
|
-
str =
|
51
|
-
str
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
unless @headers.empty? || @headers.nil?
|
56
|
-
str += ',headers=' + @headers.to_s
|
57
|
-
end
|
58
|
-
str += ']'
|
59
|
-
str.to_s
|
52
|
+
str = self.class.name
|
53
|
+
str << "[status_code=#{@status_code}"
|
54
|
+
str << ",body='#{@body}'" unless @body.nil? or @body.empty?
|
55
|
+
str << ",headers=#{headers}" unless headers.nil? or headers.empty?
|
56
|
+
str << ']'
|
60
57
|
end
|
61
58
|
end
|
62
59
|
end
|
@@ -6,9 +6,7 @@ module Ingenico::Connect::SDK
|
|
6
6
|
|
7
7
|
# Create a new header using the name and value given as parameters.
|
8
8
|
def initialize(name, value)
|
9
|
-
if name.nil?
|
10
|
-
raise ArgumentError.new('name is required')
|
11
|
-
end
|
9
|
+
raise ArgumentError.new('name is required') if name.nil? or name.strip.empty?
|
12
10
|
@name = name
|
13
11
|
@value = value
|
14
12
|
end
|
@@ -19,7 +17,7 @@ module Ingenico::Connect::SDK
|
|
19
17
|
attr_reader :value
|
20
18
|
|
21
19
|
def to_s
|
22
|
-
name
|
20
|
+
"#{name}:#{value}"
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
@@ -85,7 +85,7 @@ describe DefaultConnection do
|
|
85
85
|
).to eq(socket_timeout)
|
86
86
|
|
87
87
|
pc = connection.instance_variable_get(:@proxy_configuration)
|
88
|
-
|
88
|
+
|
89
89
|
expect(pc.host).to eq('test-proxy')
|
90
90
|
expect(pc.port).to eq(80)
|
91
91
|
expect(pc.scheme).to eq('http')
|
@@ -97,7 +97,7 @@ describe DefaultConnection do
|
|
97
97
|
end # construction
|
98
98
|
|
99
99
|
context 'sending and receiving' do
|
100
|
-
|
100
|
+
|
101
101
|
class DummyResponse
|
102
102
|
def status
|
103
103
|
200
|
@@ -142,17 +142,11 @@ describe DefaultConnection do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
let(:headers) { { 'header1' => 'dummy', 'header2' => 'yammy' } }
|
145
|
-
let(:sdk_headers)
|
146
|
-
arr = []
|
147
|
-
headers.each { |k, v| arr << Ingenico::Connect::SDK::ResponseHeader.new(k, v) }
|
148
|
-
arr
|
149
|
-
end
|
145
|
+
let(:sdk_headers) { headers.map {|k, v| Ingenico::Connect::SDK::ResponseHeader.new(k, v) } }
|
150
146
|
let(:uri) { URI('http://foobar.com/v1/1234/services/convert/amount?source=EUR&amount=1000&target=USD') }
|
151
147
|
|
152
148
|
def expected_header_str(headers)
|
153
|
-
str = ''
|
154
|
-
headers.each { |k, v| str += k + '=' + '"' + v + '"' + ', '}
|
155
|
-
str.chomp(', ')
|
149
|
+
headers.inject('') { |str, (k, v)| %Q{#{str}#{k}="#{v}", }}.chomp(', ')
|
156
150
|
end
|
157
151
|
|
158
152
|
def sdk_headers_to_s(sdk_headers)
|
@@ -7,8 +7,20 @@ describe ValueObfuscator do
|
|
7
7
|
let(:keep_start_count) { 20 }
|
8
8
|
let(:keep_end_count) { 30 }
|
9
9
|
|
10
|
+
it 'cannot be explicitly instantiated' do
|
11
|
+
expect{ValueObfuscator.new(fixed_length,
|
12
|
+
keep_start_count,
|
13
|
+
keep_end_count)
|
14
|
+
}.to raise_error(NoMethodError)
|
15
|
+
|
16
|
+
expect{ValueObfuscator.private_new(fixed_length,
|
17
|
+
keep_start_count,
|
18
|
+
keep_end_count)
|
19
|
+
}.to raise_error(NoMethodError)
|
20
|
+
end
|
21
|
+
|
10
22
|
it 'can be initialized correctly' do
|
11
|
-
sample = ValueObfuscator.send(:
|
23
|
+
sample = ValueObfuscator.send(:private_new, fixed_length,
|
12
24
|
keep_start_count, keep_end_count)
|
13
25
|
expect(sample.instance_variable_get(:@fixed_length)).to eq(10)
|
14
26
|
expect(sample.instance_variable_get(:@keep_start_count)).to eq(20)
|
@@ -51,7 +63,7 @@ describe ValueObfuscator do
|
|
51
63
|
end
|
52
64
|
|
53
65
|
context '.obfuscate_value' do
|
54
|
-
subject(:sample) { ValueObfuscator.send(:
|
66
|
+
subject(:sample) { ValueObfuscator.send(:private_new, fixed_length,
|
55
67
|
keep_start_count, keep_end_count) }
|
56
68
|
let(:value) { 'str' }
|
57
69
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connect-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ingenico ePayments
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -500,7 +500,7 @@ require_paths:
|
|
500
500
|
- lib
|
501
501
|
required_ruby_version: !ruby/object:Gem::Requirement
|
502
502
|
requirements:
|
503
|
-
- - "
|
503
|
+
- - ">="
|
504
504
|
- !ruby/object:Gem::Version
|
505
505
|
version: '2.0'
|
506
506
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -510,7 +510,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
510
510
|
version: '0'
|
511
511
|
requirements: []
|
512
512
|
rubyforge_project:
|
513
|
-
rubygems_version: 2.
|
513
|
+
rubygems_version: 2.6.8
|
514
514
|
signing_key:
|
515
515
|
specification_version: 4
|
516
516
|
summary: SDK to communicate with the GlobalCollect platform using the Ingenico Connect
|