apimatic-ci-cd-test 1.0.0
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 +7 -0
- data/LICENSE +28 -0
- data/README.md +1168 -0
- data/lib/payments_api.rb +49 -0
- data/lib/payments_api/api_helper.rb +277 -0
- data/lib/payments_api/client.rb +42 -0
- data/lib/payments_api/configuration.rb +116 -0
- data/lib/payments_api/controllers/base_controller.rb +49 -0
- data/lib/payments_api/controllers/payments_controller.rb +272 -0
- data/lib/payments_api/controllers/quotes_controller.rb +213 -0
- data/lib/payments_api/exceptions/api_exception.rb +20 -0
- data/lib/payments_api/exceptions/request_error_exception.rb +29 -0
- data/lib/payments_api/http/auth/custom_header_auth.rb +16 -0
- data/lib/payments_api/http/faraday_client.rb +70 -0
- data/lib/payments_api/http/http_call_back.rb +24 -0
- data/lib/payments_api/http/http_client.rb +104 -0
- data/lib/payments_api/http/http_method_enum.rb +13 -0
- data/lib/payments_api/http/http_request.rb +50 -0
- data/lib/payments_api/http/http_response.rb +29 -0
- data/lib/payments_api/models/address.rb +80 -0
- data/lib/payments_api/models/bank.rb +63 -0
- data/lib/payments_api/models/bank_account.rb +48 -0
- data/lib/payments_api/models/base_model.rb +47 -0
- data/lib/payments_api/models/beneficiary.rb +62 -0
- data/lib/payments_api/models/originator.rb +44 -0
- data/lib/payments_api/models/payment.rb +127 -0
- data/lib/payments_api/models/payment_details.rb +53 -0
- data/lib/payments_api/models/payment_status.rb +44 -0
- data/lib/payments_api/models/quote.rb +104 -0
- data/lib/payments_api/utilities/date_time_helper.rb +156 -0
- data/lib/payments_api/utilities/file_wrapper.rb +17 -0
- metadata +155 -0
data/lib/payments_api.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# payments_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
require 'json'
|
8
|
+
require 'faraday'
|
9
|
+
require 'certifi'
|
10
|
+
require 'logging'
|
11
|
+
|
12
|
+
require_relative 'payments_api/api_helper.rb'
|
13
|
+
require_relative 'payments_api/client.rb'
|
14
|
+
|
15
|
+
# Utilities
|
16
|
+
require_relative 'payments_api/utilities/file_wrapper.rb'
|
17
|
+
require_relative 'payments_api/utilities/date_time_helper.rb'
|
18
|
+
|
19
|
+
# Http
|
20
|
+
require_relative 'payments_api/http/http_call_back.rb'
|
21
|
+
require_relative 'payments_api/http/http_client.rb'
|
22
|
+
require_relative 'payments_api/http/faraday_client.rb'
|
23
|
+
require_relative 'payments_api/http/http_method_enum.rb'
|
24
|
+
require_relative 'payments_api/http/http_request.rb'
|
25
|
+
require_relative 'payments_api/http/http_response.rb'
|
26
|
+
require_relative 'payments_api/http/auth/custom_header_auth.rb'
|
27
|
+
|
28
|
+
# Models
|
29
|
+
require_relative 'payments_api/models/base_model.rb'
|
30
|
+
require_relative 'payments_api/models/address.rb'
|
31
|
+
require_relative 'payments_api/models/bank.rb'
|
32
|
+
require_relative 'payments_api/models/bank_account.rb'
|
33
|
+
require_relative 'payments_api/models/beneficiary.rb'
|
34
|
+
require_relative 'payments_api/models/originator.rb'
|
35
|
+
require_relative 'payments_api/models/payment.rb'
|
36
|
+
require_relative 'payments_api/models/payment_details.rb'
|
37
|
+
require_relative 'payments_api/models/payment_status.rb'
|
38
|
+
require_relative 'payments_api/models/quote.rb'
|
39
|
+
|
40
|
+
# Exceptions
|
41
|
+
require_relative 'payments_api/exceptions/api_exception.rb'
|
42
|
+
require_relative 'payments_api/exceptions/request_error_exception.rb'
|
43
|
+
|
44
|
+
require_relative 'payments_api/configuration.rb'
|
45
|
+
|
46
|
+
# Controllers
|
47
|
+
require_relative 'payments_api/controllers/base_controller.rb'
|
48
|
+
require_relative 'payments_api/controllers/quotes_controller.rb'
|
49
|
+
require_relative 'payments_api/controllers/payments_controller.rb'
|
@@ -0,0 +1,277 @@
|
|
1
|
+
# payments_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module PaymentsApi
|
7
|
+
# API utility class
|
8
|
+
class APIHelper
|
9
|
+
# Serializes an array parameter (creates key value pairs).
|
10
|
+
# @param [String] The name of the parameter.
|
11
|
+
# @param [Array] The value of the parameter.
|
12
|
+
# @param [String] The format of the serialization.
|
13
|
+
def self.serialize_array(key, array, formatting: 'indexed')
|
14
|
+
tuples = []
|
15
|
+
|
16
|
+
if formatting == 'unindexed'
|
17
|
+
tuples += array.map { |element| ["#{key}[]", element] }
|
18
|
+
elsif formatting == 'indexed'
|
19
|
+
tuples += array.map.with_index do |element, index|
|
20
|
+
["#{key}[#{index}]", element]
|
21
|
+
end
|
22
|
+
elsif formatting == 'plain'
|
23
|
+
tuples += array.map { |element| [key, element] }
|
24
|
+
else
|
25
|
+
raise ArgumentError, 'Invalid format provided.'
|
26
|
+
end
|
27
|
+
tuples
|
28
|
+
end
|
29
|
+
|
30
|
+
# Replaces template parameters in the given url.
|
31
|
+
# @param [String] The query string builder to replace the template
|
32
|
+
# parameters.
|
33
|
+
# @param [Hash] The parameters to replace in the url.
|
34
|
+
def self.append_url_with_template_parameters(query_builder, parameters)
|
35
|
+
# perform parameter validation
|
36
|
+
unless query_builder.instance_of? String
|
37
|
+
raise ArgumentError, 'Given value for parameter \"query_builder\" is
|
38
|
+
invalid.'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return if there are no parameters to replace.
|
42
|
+
return query_builder if parameters.nil?
|
43
|
+
|
44
|
+
parameters.each do |key, val|
|
45
|
+
if val.nil?
|
46
|
+
replace_value = ''
|
47
|
+
elsif val['value'].instance_of? Array
|
48
|
+
if val['encode'] == true
|
49
|
+
val['value'].map! { |element| CGI.escape(element.to_s) }
|
50
|
+
else
|
51
|
+
val['value'].map!(&:to_s)
|
52
|
+
end
|
53
|
+
replace_value = val['value'].join('/')
|
54
|
+
else
|
55
|
+
replace_value = if val['encode'] == true
|
56
|
+
CGI.escape(val['value'].to_s)
|
57
|
+
else
|
58
|
+
val['value'].to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Find the template parameter and replace it with its value.
|
63
|
+
query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
|
64
|
+
end
|
65
|
+
query_builder
|
66
|
+
end
|
67
|
+
|
68
|
+
# Appends the given set of parameters to the given query string.
|
69
|
+
# @param [String] The query string builder to add the query parameters to.
|
70
|
+
# @param [Hash] The parameters to append.
|
71
|
+
def self.append_url_with_query_parameters(query_builder, parameters)
|
72
|
+
# Perform parameter validation.
|
73
|
+
unless query_builder.instance_of? String
|
74
|
+
raise ArgumentError, 'Given value for parameter \"query_builder\"
|
75
|
+
is invalid.'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Return if there are no parameters to replace.
|
79
|
+
return query_builder if parameters.nil?
|
80
|
+
|
81
|
+
array_serialization = 'indexed'
|
82
|
+
|
83
|
+
parameters.each do |key, value|
|
84
|
+
seperator = query_builder.include?('?') ? '&' : '?'
|
85
|
+
unless value.nil?
|
86
|
+
if value.instance_of? Array
|
87
|
+
value.compact!
|
88
|
+
query_builder += if array_serialization == 'csv'
|
89
|
+
"#{seperator}#{key}=#{value.map do |element|
|
90
|
+
CGI.escape(element.to_s)
|
91
|
+
end.join(',')}"
|
92
|
+
elsif array_serialization == 'psv'
|
93
|
+
"#{seperator}#{key}=#{value.map do |element|
|
94
|
+
CGI.escape(element.to_s)
|
95
|
+
end.join('|')}"
|
96
|
+
elsif array_serialization == 'tsv'
|
97
|
+
"#{seperator}#{key}=#{value.map do |element|
|
98
|
+
CGI.escape(element.to_s)
|
99
|
+
end.join("\t")}"
|
100
|
+
else
|
101
|
+
"#{seperator}#{APIHelper.serialize_array(
|
102
|
+
key, value, formatting: array_serialization
|
103
|
+
).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
|
104
|
+
.join('&')}"
|
105
|
+
end
|
106
|
+
else
|
107
|
+
query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
query_builder
|
112
|
+
end
|
113
|
+
|
114
|
+
# Validates and processes the given Url.
|
115
|
+
# @param [String] The given Url to process.
|
116
|
+
# @return [String] Pre-processed Url as string.
|
117
|
+
def self.clean_url(url)
|
118
|
+
# Perform parameter validation.
|
119
|
+
raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
|
120
|
+
|
121
|
+
# Ensure that the urls are absolute.
|
122
|
+
matches = url.match(%r{^(https?:\/\/[^\/]+)})
|
123
|
+
raise ArgumentError, 'Invalid Url format.' if matches.nil?
|
124
|
+
|
125
|
+
# Get the http protocol match.
|
126
|
+
protocol = matches[1]
|
127
|
+
|
128
|
+
# Check if parameters exist.
|
129
|
+
index = url.index('?')
|
130
|
+
|
131
|
+
# Remove redundant forward slashes.
|
132
|
+
query = url[protocol.length...(!index.nil? ? index : url.length)]
|
133
|
+
query.gsub!(%r{\/\/+}, '/')
|
134
|
+
|
135
|
+
# Get the parameters.
|
136
|
+
parameters = !index.nil? ? url[url.index('?')...url.length] : ''
|
137
|
+
|
138
|
+
# Return processed url.
|
139
|
+
protocol + query + parameters
|
140
|
+
end
|
141
|
+
|
142
|
+
# Parses JSON string.
|
143
|
+
# @param [String] A JSON string.
|
144
|
+
def self.json_deserialize(json)
|
145
|
+
return JSON.parse(json)
|
146
|
+
rescue StandardError
|
147
|
+
raise TypeError, 'Server responded with invalid JSON.'
|
148
|
+
end
|
149
|
+
|
150
|
+
# Removes elements with empty values from a hash.
|
151
|
+
# @param [Hash] The hash to clean.
|
152
|
+
def self.clean_hash(hash)
|
153
|
+
hash.delete_if { |_key, value| value.to_s.strip.empty? }
|
154
|
+
end
|
155
|
+
|
156
|
+
# Form encodes a hash of parameters.
|
157
|
+
# @param [Hash] The hash of parameters to encode.
|
158
|
+
# @return [Hash] A hash with the same parameters form encoded.
|
159
|
+
def self.form_encode_parameters(form_parameters)
|
160
|
+
array_serialization = 'indexed'
|
161
|
+
encoded = {}
|
162
|
+
form_parameters.each do |key, value|
|
163
|
+
encoded.merge!(APIHelper.form_encode(value, key, formatting:
|
164
|
+
array_serialization))
|
165
|
+
end
|
166
|
+
encoded
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.custom_merge(a, b)
|
170
|
+
x = {}
|
171
|
+
a.each do |key, value_a|
|
172
|
+
b.each do |k, value_b|
|
173
|
+
next unless key == k
|
174
|
+
x[k] = []
|
175
|
+
if value_a.instance_of? Array
|
176
|
+
value_a.each do |v|
|
177
|
+
x[k].push(v)
|
178
|
+
end
|
179
|
+
else
|
180
|
+
x[k].push(value_a)
|
181
|
+
end
|
182
|
+
if value_b.instance_of? Array
|
183
|
+
value_b.each do |v|
|
184
|
+
x[k].push(v)
|
185
|
+
end
|
186
|
+
else
|
187
|
+
x[k].push(value_b)
|
188
|
+
end
|
189
|
+
a.delete(k)
|
190
|
+
b.delete(k)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
x.merge!(a)
|
194
|
+
x.merge!(b)
|
195
|
+
x
|
196
|
+
end
|
197
|
+
|
198
|
+
# Form encodes an object.
|
199
|
+
# @param [Dynamic] An object to form encode.
|
200
|
+
# @param [String] The name of the object.
|
201
|
+
# @return [Hash] A form encoded representation of the object in the form
|
202
|
+
# of a hash.
|
203
|
+
def self.form_encode(obj, instance_name, formatting: 'indexed')
|
204
|
+
retval = {}
|
205
|
+
|
206
|
+
serializable_types = [String, Numeric, TrueClass,
|
207
|
+
FalseClass, Date, DateTime]
|
208
|
+
|
209
|
+
# If this is a structure, resolve it's field names.
|
210
|
+
obj = obj.to_hash if obj.is_a? BaseModel
|
211
|
+
|
212
|
+
# Create a form encoded hash for this object.
|
213
|
+
if obj.nil?
|
214
|
+
nil
|
215
|
+
elsif obj.instance_of? Array
|
216
|
+
if formatting == 'indexed'
|
217
|
+
obj.each_with_index do |value, index|
|
218
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
|
219
|
+
index.to_s + ']'))
|
220
|
+
end
|
221
|
+
elsif serializable_types.map { |x| obj[0].is_a? x }.any?
|
222
|
+
obj.each do |value|
|
223
|
+
abc = if formatting == 'unindexed'
|
224
|
+
APIHelper.form_encode(value, instance_name + '[]',
|
225
|
+
formatting: formatting)
|
226
|
+
else
|
227
|
+
APIHelper.form_encode(value, instance_name,
|
228
|
+
formatting: formatting)
|
229
|
+
end
|
230
|
+
retval = APIHelper.custom_merge(retval, abc)
|
231
|
+
end
|
232
|
+
else
|
233
|
+
obj.each_with_index do |value, index|
|
234
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
|
235
|
+
index.to_s + ']', formatting: formatting))
|
236
|
+
end
|
237
|
+
end
|
238
|
+
elsif obj.instance_of? Hash
|
239
|
+
obj.each do |key, value|
|
240
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
|
241
|
+
key.to_s + ']', formatting: formatting))
|
242
|
+
end
|
243
|
+
elsif obj.instance_of? File
|
244
|
+
retval[instance_name] = UploadIO.new(
|
245
|
+
obj, 'application/octet-stream', File.basename(obj.path)
|
246
|
+
)
|
247
|
+
else
|
248
|
+
retval[instance_name] = obj
|
249
|
+
end
|
250
|
+
retval
|
251
|
+
end
|
252
|
+
|
253
|
+
# Retrieves a field from a Hash/Array based on an Array of keys/indexes
|
254
|
+
# @param [Hash, Array] The hash to extract data from
|
255
|
+
# @param [Array<String, Integer>] The keys/indexes to use
|
256
|
+
# @return [Object] The extracted value
|
257
|
+
def self.map_response(obj, keys)
|
258
|
+
val = obj
|
259
|
+
begin
|
260
|
+
keys.each do |key|
|
261
|
+
val = if val.is_a? Array
|
262
|
+
if key.to_i.to_s == key
|
263
|
+
val[key.to_i]
|
264
|
+
else
|
265
|
+
val = nil
|
266
|
+
end
|
267
|
+
else
|
268
|
+
val.fetch(key.to_sym)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
rescue NoMethodError, TypeError, IndexError
|
272
|
+
val = nil
|
273
|
+
end
|
274
|
+
val
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# payments_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module PaymentsApi
|
7
|
+
# payments_api client class.
|
8
|
+
class Client
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
# Access to quotes controller.
|
12
|
+
# @return [QuotesController] Returns the controller instance.
|
13
|
+
def quotes
|
14
|
+
@quotes ||= QuotesController.new config
|
15
|
+
end
|
16
|
+
|
17
|
+
# Access to payments controller.
|
18
|
+
# @return [PaymentsController] Returns the controller instance.
|
19
|
+
def payments
|
20
|
+
@payments ||= PaymentsController.new config
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
24
|
+
backoff_factor: 2,
|
25
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
26
|
+
retry_methods: %i[get put],
|
27
|
+
environment: Environment::PRODUCTION, x_api_key: '',
|
28
|
+
config: nil)
|
29
|
+
@config = if config.nil?
|
30
|
+
Configuration.new(timeout: timeout, max_retries: max_retries,
|
31
|
+
retry_interval: retry_interval,
|
32
|
+
backoff_factor: backoff_factor,
|
33
|
+
retry_statuses: retry_statuses,
|
34
|
+
retry_methods: retry_methods,
|
35
|
+
environment: environment,
|
36
|
+
x_api_key: x_api_key)
|
37
|
+
else
|
38
|
+
config
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# payments_api
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module PaymentsApi
|
7
|
+
# An enum for SDK environments.
|
8
|
+
class Environment
|
9
|
+
ENVIRONMENT = [
|
10
|
+
PRODUCTION = 'production'.freeze
|
11
|
+
].freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
# An enum for API servers.
|
15
|
+
class Server
|
16
|
+
SERVER = [
|
17
|
+
DEFAULT = 'default'.freeze
|
18
|
+
].freeze
|
19
|
+
end
|
20
|
+
|
21
|
+
# All configuration including auth info and base URI for the API access
|
22
|
+
# are configured in this class.
|
23
|
+
class Configuration
|
24
|
+
# The attribute readers for properties.
|
25
|
+
attr_reader :http_client
|
26
|
+
attr_reader :timeout
|
27
|
+
attr_reader :max_retries
|
28
|
+
attr_reader :retry_interval
|
29
|
+
attr_reader :backoff_factor
|
30
|
+
attr_reader :retry_statuses
|
31
|
+
attr_reader :retry_methods
|
32
|
+
attr_reader :environment
|
33
|
+
attr_reader :x_api_key
|
34
|
+
|
35
|
+
class << self
|
36
|
+
attr_reader :environments
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
40
|
+
backoff_factor: 2,
|
41
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
42
|
+
retry_methods: %i[get put],
|
43
|
+
environment: Environment::PRODUCTION, x_api_key: '')
|
44
|
+
# The value to use for connection timeout
|
45
|
+
@timeout = timeout
|
46
|
+
|
47
|
+
# The number of times to retry an endpoint call if it fails
|
48
|
+
@max_retries = max_retries
|
49
|
+
|
50
|
+
# Pause in seconds between retries
|
51
|
+
@retry_interval = retry_interval
|
52
|
+
|
53
|
+
# The amount to multiply each successive retry's interval amount
|
54
|
+
# by in order to provide backoff
|
55
|
+
@backoff_factor = backoff_factor
|
56
|
+
|
57
|
+
# A list of HTTP statuses to retry
|
58
|
+
@retry_statuses = retry_statuses
|
59
|
+
|
60
|
+
# A list of HTTP methods to retry
|
61
|
+
@retry_methods = retry_methods
|
62
|
+
|
63
|
+
# Current API environment
|
64
|
+
@environment = String(environment)
|
65
|
+
|
66
|
+
# API Key
|
67
|
+
@x_api_key = x_api_key
|
68
|
+
|
69
|
+
# The Http Client to use for making requests.
|
70
|
+
@http_client = create_http_client
|
71
|
+
end
|
72
|
+
|
73
|
+
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
|
74
|
+
backoff_factor: nil, retry_statuses: nil, retry_methods: nil,
|
75
|
+
environment: nil, x_api_key: nil)
|
76
|
+
timeout ||= self.timeout
|
77
|
+
max_retries ||= self.max_retries
|
78
|
+
retry_interval ||= self.retry_interval
|
79
|
+
backoff_factor ||= self.backoff_factor
|
80
|
+
retry_statuses ||= self.retry_statuses
|
81
|
+
retry_methods ||= self.retry_methods
|
82
|
+
environment ||= self.environment
|
83
|
+
x_api_key ||= self.x_api_key
|
84
|
+
|
85
|
+
Configuration.new(timeout: timeout, max_retries: max_retries,
|
86
|
+
retry_interval: retry_interval,
|
87
|
+
backoff_factor: backoff_factor,
|
88
|
+
retry_statuses: retry_statuses,
|
89
|
+
retry_methods: retry_methods, environment: environment,
|
90
|
+
x_api_key: x_api_key)
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_http_client
|
94
|
+
FaradayClient.new(timeout: timeout, max_retries: max_retries,
|
95
|
+
retry_interval: retry_interval,
|
96
|
+
backoff_factor: backoff_factor,
|
97
|
+
retry_statuses: retry_statuses,
|
98
|
+
retry_methods: retry_methods)
|
99
|
+
end
|
100
|
+
|
101
|
+
# All the environments the SDK can run in.
|
102
|
+
ENVIRONMENTS = {
|
103
|
+
Environment::PRODUCTION => {
|
104
|
+
Server::DEFAULT => 'https://api.payments.example.local/v1'
|
105
|
+
}
|
106
|
+
}.freeze
|
107
|
+
|
108
|
+
# Generates the appropriate base URI for the environment and the server.
|
109
|
+
# @param [Configuration::Server] The server enum for which the base URI is
|
110
|
+
# required.
|
111
|
+
# @return [String] The base URI.
|
112
|
+
def get_base_uri(server = Server::DEFAULT)
|
113
|
+
ENVIRONMENTS[environment][server].clone
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|