Module: AfterbanksPSD2
- Defined in:
- lib/afterbanks_psd2/base.rb,
lib/afterbanks_psd2/error.rb,
lib/afterbanks_psd2/version.rb,
lib/afterbanks_psd2/resource.rb,
lib/afterbanks_psd2/response.rb,
lib/afterbanks_psd2/collection.rb,
lib/afterbanks_psd2/configuration.rb,
lib/afterbanks_psd2/resources/bank.rb,
lib/afterbanks_psd2/resources/user.rb,
lib/afterbanks_psd2/resources/account.rb,
lib/afterbanks_psd2/resources/transaction.rb
Defined Under Namespace
Classes: Account, AccountNotFoundError, Bank, Collection, Configuration, ConsentWithUnfinalizedProcessError, Error, ExpiredConsentError, GenericConsentError, GenericError, GenericTransactionError, IncorrectParametersError, InvalidConsentError, InvalidConsentForProductError, MaximumNumberOfCallsReachedConsentError, ProductMismatchConsentError, Resource, Response, Transaction, User
Constant Summary
collapse
- VERSION =
"0.1.2"
Class Method Summary
collapse
Class Method Details
.api_call(method:, path:, params: {}, options: {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/afterbanks_psd2/base.rb', line 14
def api_call(method:, path:, params: {}, options: {})
options = {} if options.nil?
api_url = ENV['AFTERBANKS_API_URL'] || 'https://apipsd2.afterbanks.com'
url = api_url + path
request_params = { method: method, url: url }
if options[:timeout]
request_params.merge!(timeout: options[:timeout])
end
if method == :post
request_params.merge!(payload: params)
else
request_params.merge!(headers: { params: params })
end
response = begin
RestClient::Request.execute(**request_params)
rescue RestClient::BadRequest, RestClient::ExpectationFailed => bad_request
bad_request.response
rescue RestClient::Exceptions::ReadTimeout
log_request(
method: method,
url: url,
params: params
)
raise
end
debug_id = response.[:debug_id]
log_request(
method: method,
url: url,
params: params,
debug_id: debug_id
)
response_body = JSON.parse(response.body)
treat_errors_if_any(
response_body: response_body,
debug_id: debug_id
)
[response_body, debug_id]
end
|
.configuration ⇒ Object
6
7
8
|
# File 'lib/afterbanks_psd2/base.rb', line 6
def configuration
@configuration ||= Configuration.new
end
|
10
11
12
|
# File 'lib/afterbanks_psd2/base.rb', line 10
def configure
yield(configuration)
end
|
.log_request(method:, url:, params: {}, debug_id: nil) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/afterbanks_psd2/base.rb', line 66
def log_request(method:, url:, params: {}, debug_id: nil)
logger = AfterbanksPSD2.configuration.logger
return if logger.nil?
now = Time.now
safe_params = {}
params.each do |key, value|
safe_value = if %w{servicekey}.include?(key.to_s)
"<masked>"
else
value
end
safe_value = safe_value.to_s if safe_value.is_a?(Symbol)
safe_params[key] = safe_value
end
logger.info(
message: 'Afterbanks PSD2 request',
method: method.upcase.to_s,
url: url,
time: now.to_s,
timestamp: now.to_i,
debug_id: debug_id || 'none',
params: safe_params
)
end
|
.treat_errors_if_any(response_body:, debug_id:) ⇒ Object