partner_api 0.11.2
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/.github/workflows/release.yml +18 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +18 -0
- data/.rspec +4 -0
- data/CHANGELOG.md +105 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +17 -0
- data/bin/setup +8 -0
- data/docs/anz_api.md +67 -0
- data/docs/bnz_api.md +103 -0
- data/docs/fab_api.md +206 -0
- data/docs/gemini_api.md +184 -0
- data/docs/vma_api.md +167 -0
- data/docs/westpac_api.md +106 -0
- data/lib/anz_api/client.rb +24 -0
- data/lib/anz_api/endpoint.rb +29 -0
- data/lib/anz_api/endpoints/fetch_jwk.rb +35 -0
- data/lib/anz_api/failure_response.rb +33 -0
- data/lib/anz_api.rb +15 -0
- data/lib/bnz_api/client.rb +45 -0
- data/lib/bnz_api/configuration.rb +21 -0
- data/lib/bnz_api/endpoint.rb +56 -0
- data/lib/bnz_api/endpoints/fetch_id_token.rb +73 -0
- data/lib/bnz_api/endpoints/fetch_jwk.rb +35 -0
- data/lib/bnz_api/failure_response.rb +33 -0
- data/lib/bnz_api/httpx.rb +75 -0
- data/lib/bnz_api.rb +18 -0
- data/lib/fab_api/client.rb +36 -0
- data/lib/fab_api/configuration.rb +26 -0
- data/lib/fab_api/endpoint.rb +70 -0
- data/lib/fab_api/endpoints/deliver_email.rb +56 -0
- data/lib/fab_api/endpoints/deliver_sms.rb +51 -0
- data/lib/fab_api/endpoints/exchange_token.rb +49 -0
- data/lib/fab_api/endpoints/invalidate_token.rb +53 -0
- data/lib/fab_api/endpoints/refresh_token.rb +60 -0
- data/lib/fab_api/failure_response.rb +39 -0
- data/lib/fab_api/utils/id.rb +13 -0
- data/lib/fab_api.rb +18 -0
- data/lib/gemini_api/address.rb +23 -0
- data/lib/gemini_api/balance.rb +24 -0
- data/lib/gemini_api/client.rb +37 -0
- data/lib/gemini_api/endpoint.rb +62 -0
- data/lib/gemini_api/endpoints/create_address_request.rb +39 -0
- data/lib/gemini_api/endpoints/get_available_balances.rb +39 -0
- data/lib/gemini_api/endpoints/view_approved_addresses.rb +40 -0
- data/lib/gemini_api/endpoints/view_transfers.rb +49 -0
- data/lib/gemini_api/endpoints/withdraw_crypto_fund.rb +49 -0
- data/lib/gemini_api/failure_response.rb +47 -0
- data/lib/gemini_api/transaction.rb +14 -0
- data/lib/gemini_api/transfer.rb +44 -0
- data/lib/gemini_api.rb +16 -0
- data/lib/partner_api/endpoints/base.rb +152 -0
- data/lib/partner_api/errors.rb +18 -0
- data/lib/partner_api/utils/hash.rb +21 -0
- data/lib/partner_api/utils/read_cert.rb +38 -0
- data/lib/vma_api/client.rb +33 -0
- data/lib/vma_api/configuration.rb +24 -0
- data/lib/vma_api/endpoint.rb +29 -0
- data/lib/vma_api/endpoints/access_token.rb +60 -0
- data/lib/vma_api/endpoints/client_credentials.rb +60 -0
- data/lib/vma_api/endpoints/refresh_token.rb +60 -0
- data/lib/vma_api/endpoints/revoke_token.rb +55 -0
- data/lib/vma_api/failure_response.rb +42 -0
- data/lib/vma_api.rb +20 -0
- data/lib/westpac_api/client.rb +29 -0
- data/lib/westpac_api/configuration.rb +28 -0
- data/lib/westpac_api/endpoint.rb +26 -0
- data/lib/westpac_api/endpoints/fetch_jwk.rb +33 -0
- data/lib/westpac_api/endpoints/fetch_user.rb +96 -0
- data/lib/westpac_api/failure_response.rb +33 -0
- data/lib/westpac_api.rb +28 -0
- data/partner_api.gemspec +31 -0
- metadata +191 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'anz_api/endpoint'
|
2
|
+
|
3
|
+
module AnzApi
|
4
|
+
module Endpoints
|
5
|
+
class FetchJwk < Endpoint
|
6
|
+
prepend PartnerApi::Endpoints::Initializer
|
7
|
+
|
8
|
+
def initialize(request_id: SecureRandom.uuid)
|
9
|
+
@request_id = request_id
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :request_id
|
15
|
+
|
16
|
+
def url
|
17
|
+
config.jwks_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def method
|
21
|
+
'GET'
|
22
|
+
end
|
23
|
+
|
24
|
+
def request_options
|
25
|
+
{
|
26
|
+
headers: combined_headers
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def decode(response)
|
31
|
+
response.parse
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'partner_api/errors'
|
2
|
+
|
3
|
+
module AnzApi
|
4
|
+
class FailureResponse
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def errors
|
10
|
+
[PartnerApi::Errors::RequestError.new(message: "Invalid Response: #{body}")]
|
11
|
+
end
|
12
|
+
|
13
|
+
def error
|
14
|
+
errors.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def status
|
18
|
+
response.status
|
19
|
+
end
|
20
|
+
|
21
|
+
def body
|
22
|
+
response.body
|
23
|
+
end
|
24
|
+
|
25
|
+
def headers
|
26
|
+
response.headers.to_h
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :response
|
32
|
+
end
|
33
|
+
end
|
data/lib/anz_api.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'dry-configurable'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
require 'anz_api/client'
|
5
|
+
|
6
|
+
module AnzApi
|
7
|
+
extend Dry::Configurable
|
8
|
+
|
9
|
+
setting :logger, default: Logger.new(STDOUT, level: :info)
|
10
|
+
setting :jwks_url, constructor: proc { |value| URI.parse(value) }
|
11
|
+
|
12
|
+
setting :instrumentation, default: -> (action:, tenant_id: nil, &block) { block.call }
|
13
|
+
setting :default_parameters, default: -> { {} }
|
14
|
+
setting :default_headers, default: -> { {} }
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'bnz_api/endpoints/fetch_id_token'
|
2
|
+
require 'bnz_api/endpoints/fetch_jwk'
|
3
|
+
|
4
|
+
module BnzApi
|
5
|
+
class Client
|
6
|
+
def self.endpoint(name)
|
7
|
+
define_method(name) do |**args|
|
8
|
+
klass_name = Hanami::Utils::String.classify(name)
|
9
|
+
endpoint_klass = Hanami::Utils::Class.load!("BnzApi::Endpoints::#{klass_name}")
|
10
|
+
|
11
|
+
if config.http_persistent
|
12
|
+
init_endpoint(klass_name, endpoint_klass, **args)
|
13
|
+
else
|
14
|
+
@endpoints = nil
|
15
|
+
endpoint_klass.(config, **args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def init_endpoint(klass_name, endpoint_klass, **args)
|
21
|
+
@endpoints ||= {}
|
22
|
+
# TODO: Restructure the code so that we can have
|
23
|
+
# a cleaner implementation of caching here
|
24
|
+
# https://github.com/Kaligo/partner_api/pull/39#discussion_r1758041952
|
25
|
+
if @endpoints[klass_name]
|
26
|
+
@endpoints[klass_name].override_data(**args)
|
27
|
+
else
|
28
|
+
@endpoints[klass_name] = endpoint_klass.new(config, **args)
|
29
|
+
end
|
30
|
+
|
31
|
+
@endpoints[klass_name].call
|
32
|
+
end
|
33
|
+
|
34
|
+
endpoint :fetch_id_token
|
35
|
+
endpoint :fetch_jwk
|
36
|
+
|
37
|
+
def initialize(config: BnzApi.config)
|
38
|
+
@config = config
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :config
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'dry-configurable'
|
2
|
+
|
3
|
+
module BnzApi
|
4
|
+
class Configuration
|
5
|
+
include Dry::Configurable
|
6
|
+
|
7
|
+
setting :logger, default: Logger.new(STDOUT, level: :info)
|
8
|
+
setting :token_url, constructor: proc { |value| URI.parse(value) }
|
9
|
+
setting :jwks_url, constructor: proc { |value| URI.parse(value) }
|
10
|
+
|
11
|
+
setting :token_exchange do
|
12
|
+
setting :public_key
|
13
|
+
setting :private_key
|
14
|
+
end
|
15
|
+
|
16
|
+
setting :default_parameters, default: -> { {} }
|
17
|
+
setting :default_headers, default: -> { {} }
|
18
|
+
setting :instrumentation, default: -> (action:, tenant_id: nil, &block) { block.call }
|
19
|
+
setting :http_persistent, default: false
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'partner_api/endpoints/base'
|
2
|
+
require 'bnz_api/failure_response'
|
3
|
+
require 'http'
|
4
|
+
require_relative './httpx'
|
5
|
+
|
6
|
+
module BnzApi
|
7
|
+
class Endpoint < PartnerApi::Endpoints::Base
|
8
|
+
|
9
|
+
def override_data(_args); end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def client
|
14
|
+
# TODO: Remove `http_persistent` after the trial is successful
|
15
|
+
@client ||=
|
16
|
+
if config.http_persistent
|
17
|
+
HTTPX.with(debug: config.logger).plugin(:persistent)
|
18
|
+
else
|
19
|
+
HTTP::Client.new(**connection_options)
|
20
|
+
.use(logging: { logger: config.logger })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection_options
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
|
28
|
+
def decode(response)
|
29
|
+
if config.http_persistent
|
30
|
+
JSON.parse(response.body.to_s)
|
31
|
+
else
|
32
|
+
response.parse
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def successful?(response)
|
37
|
+
if config.http_persistent
|
38
|
+
response.error.nil?
|
39
|
+
else
|
40
|
+
response.status.success?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def decode_error(response)
|
45
|
+
if config.http_persistent && response.is_a?(HTTPX::ErrorResponse)
|
46
|
+
raise Errors::ConnectionError, response.error.message
|
47
|
+
end
|
48
|
+
|
49
|
+
FailureResponse.new(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def logging_params
|
53
|
+
{ request_id: request_id }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'bnz_api/endpoint'
|
2
|
+
|
3
|
+
module BnzApi
|
4
|
+
module Endpoints
|
5
|
+
class FetchIdToken < Endpoint
|
6
|
+
prepend PartnerApi::Endpoints::Initializer
|
7
|
+
|
8
|
+
def initialize(auth_code:, redirect_uri:, client_id:, request_id: SecureRandom.uuid)
|
9
|
+
@auth_code = auth_code
|
10
|
+
@redirect_uri = redirect_uri
|
11
|
+
@client_id = client_id
|
12
|
+
@request_id = request_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def override_data(auth_code:, redirect_uri:, client_id:, request_id: SecureRandom.uuid)
|
16
|
+
@auth_code = auth_code
|
17
|
+
@redirect_uri = redirect_uri
|
18
|
+
@client_id = client_id
|
19
|
+
@request_id = request_id
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :auth_code, :redirect_uri, :client_id, :request_id
|
25
|
+
|
26
|
+
def method
|
27
|
+
'POST'
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
config.token_url
|
32
|
+
end
|
33
|
+
|
34
|
+
def headers
|
35
|
+
{ 'Content-Type' => 'application/x-www-form-urlencoded' }
|
36
|
+
end
|
37
|
+
|
38
|
+
def request_options
|
39
|
+
{ headers: combined_headers, form: parameters }
|
40
|
+
end
|
41
|
+
|
42
|
+
def connection_options
|
43
|
+
super.merge(ssl_options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def api_config
|
47
|
+
config.token_exchange
|
48
|
+
end
|
49
|
+
|
50
|
+
def ssl_options
|
51
|
+
@ssl_options ||=
|
52
|
+
if api_config.public_key && api_config.private_key
|
53
|
+
ssl_context = PartnerApi::Utils::ReadCert
|
54
|
+
.new(api_config.public_key, api_config.private_key)
|
55
|
+
.ssl_context
|
56
|
+
|
57
|
+
{ ssl_context: ssl_context }
|
58
|
+
else
|
59
|
+
{}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def parameters
|
64
|
+
{
|
65
|
+
'grant_type' => 'authorization_code',
|
66
|
+
'redirect_uri' => redirect_uri,
|
67
|
+
'code' => auth_code,
|
68
|
+
'client_id' => client_id
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'bnz_api/endpoint'
|
2
|
+
|
3
|
+
module BnzApi
|
4
|
+
module Endpoints
|
5
|
+
class FetchJwk < Endpoint
|
6
|
+
prepend PartnerApi::Endpoints::Initializer
|
7
|
+
|
8
|
+
def initialize(request_id: SecureRandom.uuid)
|
9
|
+
@request_id = request_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def override_data(request_id: SecureRandom.uuid)
|
13
|
+
@request_id = request_id
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :request_id
|
19
|
+
|
20
|
+
def url
|
21
|
+
config.jwks_url
|
22
|
+
end
|
23
|
+
|
24
|
+
def method
|
25
|
+
'GET'
|
26
|
+
end
|
27
|
+
|
28
|
+
def request_options
|
29
|
+
{
|
30
|
+
headers: combined_headers
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'partner_api/errors'
|
2
|
+
|
3
|
+
module BnzApi
|
4
|
+
class FailureResponse
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def errors
|
10
|
+
[PartnerApi::Errors::RequestError.new(message: "Invalid Response: #{body}")]
|
11
|
+
end
|
12
|
+
|
13
|
+
def error
|
14
|
+
errors.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def status
|
18
|
+
response.status
|
19
|
+
end
|
20
|
+
|
21
|
+
def body
|
22
|
+
response.body
|
23
|
+
end
|
24
|
+
|
25
|
+
def headers
|
26
|
+
response.headers.to_h
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :response
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE: There is a conflict between `httpx` and `event_tracer`:
|
4
|
+
# - `httpx` will load the dependencies of `datadog` gem when the module `Datadog` is defined
|
5
|
+
# - Some of our apps use `datadog/statsd` as one of its loggers, which defines `Datadog` module
|
6
|
+
# => As a result, there will be LoadError because non of our apps are having `datadog` gem installed
|
7
|
+
# Therefore, we use this monkey-patch to skip loading the dependencies of `datadog` gem completely
|
8
|
+
# as we are not using that service anyway
|
9
|
+
# References:
|
10
|
+
# - https://github.com/HoneyryderChuck/httpx/blob/40b4884d878033b84697d2afb4dfe92425c8e379/lib/httpx.rb#L65
|
11
|
+
# - https://github.com/Kaligo/guardhouse/blob/e11c16f12366012e577832383327c06fe89847a4/config/initializers/event_tracer.rb#L1
|
12
|
+
|
13
|
+
require "httpx/version"
|
14
|
+
|
15
|
+
require "httpx/extensions"
|
16
|
+
|
17
|
+
require "httpx/errors"
|
18
|
+
require "httpx/utils"
|
19
|
+
require "httpx/punycode"
|
20
|
+
require "httpx/domain_name"
|
21
|
+
require "httpx/altsvc"
|
22
|
+
require "httpx/callbacks"
|
23
|
+
require "httpx/loggable"
|
24
|
+
require "httpx/transcoder"
|
25
|
+
require "httpx/timers"
|
26
|
+
require "httpx/pool"
|
27
|
+
require "httpx/headers"
|
28
|
+
require "httpx/request"
|
29
|
+
require "httpx/response"
|
30
|
+
require "httpx/options"
|
31
|
+
require "httpx/chainable"
|
32
|
+
|
33
|
+
# Top-Level Namespace
|
34
|
+
#
|
35
|
+
module HTTPX
|
36
|
+
EMPTY = [].freeze
|
37
|
+
|
38
|
+
# All plugins should be stored under this module/namespace. Can register and load
|
39
|
+
# plugins.
|
40
|
+
#
|
41
|
+
module Plugins
|
42
|
+
@plugins = {}
|
43
|
+
@plugins_mutex = Thread::Mutex.new
|
44
|
+
|
45
|
+
# Loads a plugin based on a name. If the plugin hasn't been loaded, tries to load
|
46
|
+
# it from the load path under "httpx/plugins/" directory.
|
47
|
+
#
|
48
|
+
def self.load_plugin(name)
|
49
|
+
h = @plugins
|
50
|
+
m = @plugins_mutex
|
51
|
+
unless (plugin = m.synchronize { h[name] })
|
52
|
+
require "httpx/plugins/#{name}"
|
53
|
+
raise "Plugin #{name} hasn't been registered" unless (plugin = m.synchronize { h[name] })
|
54
|
+
end
|
55
|
+
plugin
|
56
|
+
end
|
57
|
+
|
58
|
+
# Registers a plugin (+mod+) in the central store indexed by +name+.
|
59
|
+
#
|
60
|
+
def self.register_plugin(name, mod)
|
61
|
+
h = @plugins
|
62
|
+
m = @plugins_mutex
|
63
|
+
m.synchronize { h[name] = mod }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
extend Chainable
|
68
|
+
end
|
69
|
+
|
70
|
+
require "httpx/session"
|
71
|
+
require "httpx/session_extensions"
|
72
|
+
|
73
|
+
# load integrations when possible
|
74
|
+
require "httpx/adapters/sentry" if defined?(Sentry)
|
75
|
+
require "httpx/adapters/webmock" if defined?(WebMock)
|
data/lib/bnz_api.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'concurrent-ruby'
|
3
|
+
|
4
|
+
require 'bnz_api/client'
|
5
|
+
require 'bnz_api/configuration'
|
6
|
+
|
7
|
+
module BnzApi
|
8
|
+
extend self
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
@configuration = Concurrent::Hash.new
|
12
|
+
|
13
|
+
def_delegators 'configuration(:default)', :config, :configure
|
14
|
+
|
15
|
+
def configuration(key)
|
16
|
+
@configuration[key] ||= Configuration.new
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'hanami/utils/string'
|
2
|
+
require 'hanami/utils/class'
|
3
|
+
|
4
|
+
require 'fab_api/endpoints/deliver_email'
|
5
|
+
require 'fab_api/endpoints/deliver_sms'
|
6
|
+
require 'fab_api/endpoints/refresh_token'
|
7
|
+
require 'fab_api/endpoints/exchange_token'
|
8
|
+
require 'fab_api/endpoints/invalidate_token'
|
9
|
+
|
10
|
+
module FabApi
|
11
|
+
class Client
|
12
|
+
def self.endpoint(name)
|
13
|
+
define_method(name) do |**args|
|
14
|
+
klass_name = Hanami::Utils::String.classify(name)
|
15
|
+
endpoint_klass = Hanami::Utils::Class.load!("FabApi::Endpoints::#{klass_name}")
|
16
|
+
|
17
|
+
endpoint_klass.(config, **args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
endpoint :deliver_email
|
22
|
+
endpoint :deliver_sms
|
23
|
+
|
24
|
+
endpoint :refresh_token
|
25
|
+
endpoint :exchange_token
|
26
|
+
endpoint :invalidate_token
|
27
|
+
|
28
|
+
def initialize(config: FabApi.config)
|
29
|
+
@config = config
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :config
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'dry-configurable'
|
2
|
+
|
3
|
+
module FabApi
|
4
|
+
class Configuration
|
5
|
+
include Dry::Configurable
|
6
|
+
|
7
|
+
setting :logger, default: Logger.new(STDOUT, level: :info)
|
8
|
+
|
9
|
+
setting :base_url, constructor: proc { |value| URI.parse(value) }
|
10
|
+
|
11
|
+
setting :proxy_address
|
12
|
+
setting :proxy_port
|
13
|
+
setting :public_key
|
14
|
+
setting :private_key
|
15
|
+
|
16
|
+
setting :default_parameters, default: -> {
|
17
|
+
{
|
18
|
+
"applicationArea": {
|
19
|
+
"transactionDateTime": Time.now.strftime('%F %H:%M:%S%z'),
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
setting :default_headers, default: -> { {} }
|
24
|
+
setting :instrumentation, default: -> (action:, tenant_id: nil, &block) { block.call }
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'partner_api/endpoints/base'
|
2
|
+
require 'fab_api/failure_response'
|
3
|
+
|
4
|
+
module FabApi
|
5
|
+
class Endpoint < PartnerApi::Endpoints::Base
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection_options
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
if ssl_options.any?
|
13
|
+
options.merge!(ssl_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
if proxy_options.any?
|
17
|
+
options.merge!(proxy: proxy_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
options
|
21
|
+
end
|
22
|
+
|
23
|
+
def proxy_options
|
24
|
+
@proxy_options ||= {
|
25
|
+
proxy_address: config.proxy_address,
|
26
|
+
proxy_port: config.proxy_port ? config.proxy_port.to_i : nil
|
27
|
+
}.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
def ssl_options
|
31
|
+
@ssl_options ||=
|
32
|
+
if config.public_key && config.private_key
|
33
|
+
ssl_context = OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
34
|
+
ctx.ssl_version = :TLSv1_2 # FAB requires TLS v1.2
|
35
|
+
|
36
|
+
ctx.set_params(
|
37
|
+
cert: OpenSSL::X509::Certificate.new(config.public_key),
|
38
|
+
key: OpenSSL::PKey::RSA.new(config.private_key)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
{ ssl_context: ssl_context }
|
43
|
+
else
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_headers
|
49
|
+
{ "Content-Type" => "application/json" }
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_parameters
|
53
|
+
{
|
54
|
+
"applicationArea" => {
|
55
|
+
"senderId" => "ASC",
|
56
|
+
"countryOfOrigin" => "AE"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def successful?(response)
|
62
|
+
response.status.success? &&
|
63
|
+
response.parse(:json).dig("responseStatus", "status") == "SUCCESS"
|
64
|
+
end
|
65
|
+
|
66
|
+
def decode_error(response)
|
67
|
+
FailureResponse.new(response)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'fab_api/endpoint'
|
2
|
+
|
3
|
+
module FabApi
|
4
|
+
module Endpoints
|
5
|
+
class DeliverEmail < Endpoint
|
6
|
+
prepend PartnerApi::Endpoints::Initializer
|
7
|
+
|
8
|
+
def initialize(partner_user_id:, notification_id:, subject:, message:)
|
9
|
+
@partner_user_id = partner_user_id
|
10
|
+
@notification_id = notification_id
|
11
|
+
@subject = subject
|
12
|
+
@message = message
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :partner_user_id, :notification_id, :subject, :message
|
18
|
+
|
19
|
+
def method
|
20
|
+
"POST"
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
"/communication/v1/send/email"
|
25
|
+
end
|
26
|
+
|
27
|
+
def parameters
|
28
|
+
{
|
29
|
+
"applicationArea": {
|
30
|
+
"transactionId": notification_id,
|
31
|
+
"correlationId": notification_id
|
32
|
+
},
|
33
|
+
"dataArea": {
|
34
|
+
"customerIdentifier": partner_user_id,
|
35
|
+
"emailSubject": subject,
|
36
|
+
"emailBodyContent": message,
|
37
|
+
"emailBodyContentType": "text/html",
|
38
|
+
"fromAddress": "FAB <donotreply@bankfab.com>",
|
39
|
+
"fromEntityName": "FAB"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
# rubocop:enable Metrics/MethodLength
|
44
|
+
|
45
|
+
def decode(_response); end
|
46
|
+
|
47
|
+
def logging_params
|
48
|
+
{
|
49
|
+
transaction_id: notification_id,
|
50
|
+
correlation_id: notification_id,
|
51
|
+
customer_identifier: partner_user_id
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fab_api/endpoint'
|
2
|
+
|
3
|
+
module FabApi
|
4
|
+
module Endpoints
|
5
|
+
class DeliverSms < Endpoint
|
6
|
+
prepend PartnerApi::Endpoints::Initializer
|
7
|
+
|
8
|
+
def initialize(partner_user_id:, notification_id:, message:)
|
9
|
+
@partner_user_id = partner_user_id
|
10
|
+
@notification_id = notification_id
|
11
|
+
@message = message
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :partner_user_id, :notification_id, :message
|
17
|
+
|
18
|
+
def method
|
19
|
+
"POST"
|
20
|
+
end
|
21
|
+
|
22
|
+
def path
|
23
|
+
"/communication/v1/send/sms"
|
24
|
+
end
|
25
|
+
|
26
|
+
def parameters
|
27
|
+
{
|
28
|
+
"applicationArea" => {
|
29
|
+
"transactionId" => notification_id,
|
30
|
+
"correlationId" => notification_id
|
31
|
+
},
|
32
|
+
"dataArea" => {
|
33
|
+
"customerIdentifier" => partner_user_id,
|
34
|
+
"messageText" => message,
|
35
|
+
"originatorName" => "FAB"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def decode(_response); end
|
41
|
+
|
42
|
+
def logging_params
|
43
|
+
{
|
44
|
+
transaction_id: notification_id,
|
45
|
+
correlation_id: notification_id,
|
46
|
+
customer_identifier: partner_user_id
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|