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.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/release.yml +18 -0
  3. data/.github/workflows/ruby.yml +28 -0
  4. data/.gitignore +18 -0
  5. data/.rspec +4 -0
  6. data/CHANGELOG.md +105 -0
  7. data/Gemfile +10 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +85 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +17 -0
  12. data/bin/setup +8 -0
  13. data/docs/anz_api.md +67 -0
  14. data/docs/bnz_api.md +103 -0
  15. data/docs/fab_api.md +206 -0
  16. data/docs/gemini_api.md +184 -0
  17. data/docs/vma_api.md +167 -0
  18. data/docs/westpac_api.md +106 -0
  19. data/lib/anz_api/client.rb +24 -0
  20. data/lib/anz_api/endpoint.rb +29 -0
  21. data/lib/anz_api/endpoints/fetch_jwk.rb +35 -0
  22. data/lib/anz_api/failure_response.rb +33 -0
  23. data/lib/anz_api.rb +15 -0
  24. data/lib/bnz_api/client.rb +45 -0
  25. data/lib/bnz_api/configuration.rb +21 -0
  26. data/lib/bnz_api/endpoint.rb +56 -0
  27. data/lib/bnz_api/endpoints/fetch_id_token.rb +73 -0
  28. data/lib/bnz_api/endpoints/fetch_jwk.rb +35 -0
  29. data/lib/bnz_api/failure_response.rb +33 -0
  30. data/lib/bnz_api/httpx.rb +75 -0
  31. data/lib/bnz_api.rb +18 -0
  32. data/lib/fab_api/client.rb +36 -0
  33. data/lib/fab_api/configuration.rb +26 -0
  34. data/lib/fab_api/endpoint.rb +70 -0
  35. data/lib/fab_api/endpoints/deliver_email.rb +56 -0
  36. data/lib/fab_api/endpoints/deliver_sms.rb +51 -0
  37. data/lib/fab_api/endpoints/exchange_token.rb +49 -0
  38. data/lib/fab_api/endpoints/invalidate_token.rb +53 -0
  39. data/lib/fab_api/endpoints/refresh_token.rb +60 -0
  40. data/lib/fab_api/failure_response.rb +39 -0
  41. data/lib/fab_api/utils/id.rb +13 -0
  42. data/lib/fab_api.rb +18 -0
  43. data/lib/gemini_api/address.rb +23 -0
  44. data/lib/gemini_api/balance.rb +24 -0
  45. data/lib/gemini_api/client.rb +37 -0
  46. data/lib/gemini_api/endpoint.rb +62 -0
  47. data/lib/gemini_api/endpoints/create_address_request.rb +39 -0
  48. data/lib/gemini_api/endpoints/get_available_balances.rb +39 -0
  49. data/lib/gemini_api/endpoints/view_approved_addresses.rb +40 -0
  50. data/lib/gemini_api/endpoints/view_transfers.rb +49 -0
  51. data/lib/gemini_api/endpoints/withdraw_crypto_fund.rb +49 -0
  52. data/lib/gemini_api/failure_response.rb +47 -0
  53. data/lib/gemini_api/transaction.rb +14 -0
  54. data/lib/gemini_api/transfer.rb +44 -0
  55. data/lib/gemini_api.rb +16 -0
  56. data/lib/partner_api/endpoints/base.rb +152 -0
  57. data/lib/partner_api/errors.rb +18 -0
  58. data/lib/partner_api/utils/hash.rb +21 -0
  59. data/lib/partner_api/utils/read_cert.rb +38 -0
  60. data/lib/vma_api/client.rb +33 -0
  61. data/lib/vma_api/configuration.rb +24 -0
  62. data/lib/vma_api/endpoint.rb +29 -0
  63. data/lib/vma_api/endpoints/access_token.rb +60 -0
  64. data/lib/vma_api/endpoints/client_credentials.rb +60 -0
  65. data/lib/vma_api/endpoints/refresh_token.rb +60 -0
  66. data/lib/vma_api/endpoints/revoke_token.rb +55 -0
  67. data/lib/vma_api/failure_response.rb +42 -0
  68. data/lib/vma_api.rb +20 -0
  69. data/lib/westpac_api/client.rb +29 -0
  70. data/lib/westpac_api/configuration.rb +28 -0
  71. data/lib/westpac_api/endpoint.rb +26 -0
  72. data/lib/westpac_api/endpoints/fetch_jwk.rb +33 -0
  73. data/lib/westpac_api/endpoints/fetch_user.rb +96 -0
  74. data/lib/westpac_api/failure_response.rb +33 -0
  75. data/lib/westpac_api.rb +28 -0
  76. data/partner_api.gemspec +31 -0
  77. metadata +191 -0
@@ -0,0 +1,29 @@
1
+ require 'hanami/utils/string'
2
+ require 'hanami/utils/class'
3
+
4
+ require 'westpac_api/endpoints/fetch_jwk'
5
+ require 'westpac_api/endpoints/fetch_user'
6
+
7
+ module WestpacApi
8
+ class Client
9
+ def self.endpoint(name)
10
+ define_method(name) do |**args|
11
+ klass_name = Hanami::Utils::String.classify(name)
12
+ endpoint_klass = Hanami::Utils::Class.load!("WestpacApi::Endpoints::#{klass_name}")
13
+
14
+ endpoint_klass.(config, **args)
15
+ end
16
+ end
17
+
18
+ endpoint :fetch_jwk
19
+ endpoint :fetch_user
20
+
21
+ def initialize(config:)
22
+ @config = config
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :config
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'dry-configurable'
2
+ require 'uri/http'
3
+
4
+ module WestpacApi
5
+ class Configuration
6
+ include Dry::Configurable
7
+
8
+ setting :logger, default: Logger.new(STDOUT, level: :info)
9
+ setting :jwk_url
10
+ setting :context_api do
11
+ setting :url
12
+ setting :username
13
+ setting :password
14
+ setting :proxy_address
15
+ setting :proxy_port
16
+ setting :public_key
17
+ setting :private_key
18
+ end
19
+ setting :default_headers, default: -> { {} }
20
+ setting :default_parameters, default: -> { {} }
21
+ setting :instrumentation, default: -> (action:, tenant_id: nil, &block) { block.call }
22
+
23
+ def match_issuer?(issuer)
24
+ parsed_jwk_url = URI.parse(config.jwk_url)
25
+ parsed_jwk_url.host == issuer
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'partner_api/endpoints/base'
4
+ require 'westpac_api/failure_response'
5
+
6
+ module WestpacApi
7
+ class Endpoint < PartnerApi::Endpoints::Base
8
+ private
9
+
10
+ def connection_options
11
+ {}
12
+ end
13
+
14
+ def successful?(response)
15
+ response.status.success?
16
+ end
17
+
18
+ def decode_error(response)
19
+ FailureResponse.new(response)
20
+ end
21
+
22
+ def logging_params
23
+ { request_id: request_id }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ require 'westpac_api/endpoint'
2
+
3
+ module WestpacApi
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
+ URI.parse(config.jwk_url)
18
+ end
19
+
20
+ def method
21
+ 'GET'
22
+ end
23
+
24
+ def decode(response)
25
+ response.parse
26
+ end
27
+
28
+ def request_options
29
+ { headers: { "Request-ID" => request_id } }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,96 @@
1
+ require 'westpac_api/endpoint'
2
+
3
+ module WestpacApi
4
+ module Endpoints
5
+ class FetchUser < Endpoint
6
+ prepend PartnerApi::Endpoints::Initializer
7
+
8
+ def initialize(user_id:, context_reference_id:, correlation_id: SecureRandom.uuid, message_id: SecureRandom.uuid)
9
+ @user_id = user_id
10
+ @context_reference_id = context_reference_id
11
+ @correlation_id = correlation_id
12
+ @message_id = message_id
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :user_id, :context_reference_id, :correlation_id, :message_id
18
+
19
+ def api_config
20
+ config.context_api
21
+ end
22
+
23
+ def client
24
+ super.basic_auth(
25
+ user: api_config.username,
26
+ pass: api_config.password
27
+ )
28
+ end
29
+
30
+ def url
31
+ URI.parse(api_config.url)
32
+ end
33
+
34
+ def method
35
+ 'POST'
36
+ end
37
+
38
+ def headers
39
+ {
40
+ 'Content-Type' => 'application/json',
41
+ 'x-messageId' => message_id,
42
+ 'x-appcorrelationid' => correlation_id
43
+ }
44
+ end
45
+
46
+ def parameters
47
+ {
48
+ contextReferenceNumber: context_reference_id,
49
+ externalCustomerReferenceId: user_id
50
+ }
51
+ end
52
+
53
+ def decode(response)
54
+ response.parse
55
+ end
56
+
57
+ def logging_params
58
+ { correlation_id: correlation_id, message_id: message_id }
59
+ end
60
+
61
+ def connection_options
62
+ options = {}
63
+
64
+ if ssl_options.any?
65
+ options.merge!(ssl_options)
66
+ end
67
+
68
+ if proxy_options.any?
69
+ options.merge!(proxy: proxy_options)
70
+ end
71
+
72
+ options
73
+ end
74
+
75
+ def proxy_options
76
+ @proxy_options ||= {
77
+ proxy_address: api_config.proxy_address,
78
+ proxy_port: api_config.proxy_port
79
+ }.compact
80
+ end
81
+
82
+ def ssl_options
83
+ @ssl_options ||=
84
+ if api_config.public_key && api_config.private_key
85
+ ssl_context = PartnerApi::Utils::ReadCert
86
+ .new(api_config.public_key, api_config.private_key)
87
+ .ssl_context
88
+
89
+ { ssl_context: ssl_context }
90
+ else
91
+ {}
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,33 @@
1
+ require 'partner_api/errors'
2
+
3
+ module WestpacApi
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,28 @@
1
+ require 'forwardable'
2
+
3
+ require 'westpac_api/client'
4
+ require 'westpac_api/configuration'
5
+
6
+ module WestpacApi
7
+ extend self
8
+ extend Forwardable
9
+
10
+ @configurations = Concurrent::Hash.new
11
+
12
+ def_delegators 'configuration(:default)', :config, :configure
13
+
14
+ def configuration(key)
15
+ @configurations[key] ||= Configuration.new
16
+ end
17
+
18
+ def fetch_config_by_issuer(issuer)
19
+ desired_configuration =
20
+ @configurations.select { |_, config| config.match_issuer?(issuer) }.values
21
+
22
+ raise 'The desired configuration cannot be found' if desired_configuration.empty?
23
+
24
+ raise "There is more than one configuration for #{issuer}" if desired_configuration.size > 1
25
+
26
+ desired_configuration.first
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "partner_api"
3
+ spec.version = '0.11.2'
4
+ spec.authors = ["Hieu Nguyen"]
5
+ spec.email = ["hieuk09@gmail.com"]
6
+
7
+ spec.summary = %q{API client for Ascenda Partners}
8
+ spec.description = %q{API client for Ascenda Partners}
9
+ spec.homepage = "https://github.com/kaligo/partner_api"
10
+ spec.license = "MIT"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = "https://github.com/kaligo/partner_api"
15
+ spec.metadata["changelog_uri"] = "https://github.com/Kaligo/partner_api/blob/master/changelog.md"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "dry-monads", "~> 1.0"
27
+ spec.add_dependency "dry-configurable", ">= 0.13"
28
+ spec.add_dependency "hanami-utils", "~> 1.0"
29
+ spec.add_dependency 'http', '~> 5.0'
30
+ spec.add_dependency 'httpx', '>= 0.24.6'
31
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: partner_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.2
5
+ platform: ruby
6
+ authors:
7
+ - Hieu Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-monads
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.13'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hanami-utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httpx
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.24.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.24.6
83
+ description: API client for Ascenda Partners
84
+ email:
85
+ - hieuk09@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".github/workflows/release.yml"
91
+ - ".github/workflows/ruby.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - CHANGELOG.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - docs/anz_api.md
102
+ - docs/bnz_api.md
103
+ - docs/fab_api.md
104
+ - docs/gemini_api.md
105
+ - docs/vma_api.md
106
+ - docs/westpac_api.md
107
+ - lib/anz_api.rb
108
+ - lib/anz_api/client.rb
109
+ - lib/anz_api/endpoint.rb
110
+ - lib/anz_api/endpoints/fetch_jwk.rb
111
+ - lib/anz_api/failure_response.rb
112
+ - lib/bnz_api.rb
113
+ - lib/bnz_api/client.rb
114
+ - lib/bnz_api/configuration.rb
115
+ - lib/bnz_api/endpoint.rb
116
+ - lib/bnz_api/endpoints/fetch_id_token.rb
117
+ - lib/bnz_api/endpoints/fetch_jwk.rb
118
+ - lib/bnz_api/failure_response.rb
119
+ - lib/bnz_api/httpx.rb
120
+ - lib/fab_api.rb
121
+ - lib/fab_api/client.rb
122
+ - lib/fab_api/configuration.rb
123
+ - lib/fab_api/endpoint.rb
124
+ - lib/fab_api/endpoints/deliver_email.rb
125
+ - lib/fab_api/endpoints/deliver_sms.rb
126
+ - lib/fab_api/endpoints/exchange_token.rb
127
+ - lib/fab_api/endpoints/invalidate_token.rb
128
+ - lib/fab_api/endpoints/refresh_token.rb
129
+ - lib/fab_api/failure_response.rb
130
+ - lib/fab_api/utils/id.rb
131
+ - lib/gemini_api.rb
132
+ - lib/gemini_api/address.rb
133
+ - lib/gemini_api/balance.rb
134
+ - lib/gemini_api/client.rb
135
+ - lib/gemini_api/endpoint.rb
136
+ - lib/gemini_api/endpoints/create_address_request.rb
137
+ - lib/gemini_api/endpoints/get_available_balances.rb
138
+ - lib/gemini_api/endpoints/view_approved_addresses.rb
139
+ - lib/gemini_api/endpoints/view_transfers.rb
140
+ - lib/gemini_api/endpoints/withdraw_crypto_fund.rb
141
+ - lib/gemini_api/failure_response.rb
142
+ - lib/gemini_api/transaction.rb
143
+ - lib/gemini_api/transfer.rb
144
+ - lib/partner_api/endpoints/base.rb
145
+ - lib/partner_api/errors.rb
146
+ - lib/partner_api/utils/hash.rb
147
+ - lib/partner_api/utils/read_cert.rb
148
+ - lib/vma_api.rb
149
+ - lib/vma_api/client.rb
150
+ - lib/vma_api/configuration.rb
151
+ - lib/vma_api/endpoint.rb
152
+ - lib/vma_api/endpoints/access_token.rb
153
+ - lib/vma_api/endpoints/client_credentials.rb
154
+ - lib/vma_api/endpoints/refresh_token.rb
155
+ - lib/vma_api/endpoints/revoke_token.rb
156
+ - lib/vma_api/failure_response.rb
157
+ - lib/westpac_api.rb
158
+ - lib/westpac_api/client.rb
159
+ - lib/westpac_api/configuration.rb
160
+ - lib/westpac_api/endpoint.rb
161
+ - lib/westpac_api/endpoints/fetch_jwk.rb
162
+ - lib/westpac_api/endpoints/fetch_user.rb
163
+ - lib/westpac_api/failure_response.rb
164
+ - partner_api.gemspec
165
+ homepage: https://github.com/kaligo/partner_api
166
+ licenses:
167
+ - MIT
168
+ metadata:
169
+ homepage_uri: https://github.com/kaligo/partner_api
170
+ source_code_uri: https://github.com/kaligo/partner_api
171
+ changelog_uri: https://github.com/Kaligo/partner_api/blob/master/changelog.md
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 2.6.0
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubygems_version: 3.4.19
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: API client for Ascenda Partners
191
+ test_files: []