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
data/docs/fab_api.md
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
# FabApi Usage
|
2
|
+
|
3
|
+
* [Configuration](#configuration)
|
4
|
+
* [Handle errors](#handle-errors)
|
5
|
+
* Endpoints
|
6
|
+
* [Deliver Email](#deliver-email)
|
7
|
+
* [Deliver SMS](#deliver-sms)
|
8
|
+
* [Exchange access token for OAuth token](#exchange-access-token-for-oauth-token)
|
9
|
+
* [Fetch new OAuth token using refresh token](#fetch-new-oauth-token-using-refresh-token)
|
10
|
+
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
FabApi.configure do |config|
|
16
|
+
config.logger = Logger.new # default: log to STDOUT, level info
|
17
|
+
|
18
|
+
config.base_url = 'http://fab.com'
|
19
|
+
|
20
|
+
# if both proxy config is empty, it does not use proxy
|
21
|
+
config.proxy_address = '123.12.11.10'
|
22
|
+
config.proxy_port = 8280
|
23
|
+
|
24
|
+
config.public_key = 'somecert' # SSL cert for mutual SSL
|
25
|
+
config.private_key = 'somekey' # SSL private key for mutual SSL
|
26
|
+
|
27
|
+
# by default, it sets
|
28
|
+
# transactionDateTime: Time.now.strftime('%F %H:%M:%S%z')
|
29
|
+
# senderId: "ASC"
|
30
|
+
# countryOfOrigin: "AE"
|
31
|
+
config.default_parameters = -> {
|
32
|
+
{
|
33
|
+
"applicationArea": {
|
34
|
+
"transactionDateTime": Time.current.iso_8601
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
# by default, it sets content-type as json
|
40
|
+
config.default_headers = -> {
|
41
|
+
{
|
42
|
+
'Request-ID' => Current.request_id
|
43
|
+
}
|
44
|
+
}
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
We can also configure on-the-fly using `Configuration` class:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
config = FabApi::Configuration.new.configure do |c|
|
52
|
+
c.public_key = 'new_cert'
|
53
|
+
c.private_key = 'new_key'
|
54
|
+
end
|
55
|
+
|
56
|
+
client = FabApi::Client.new(config: config)
|
57
|
+
```
|
58
|
+
|
59
|
+
---
|
60
|
+
|
61
|
+
## Handle errors
|
62
|
+
|
63
|
+
The client is consistent in error handling, this works accross all method calls:
|
64
|
+
|
65
|
+
- When there are connection errors, it raises `PartnerApi::Errors::ConnectionError`
|
66
|
+
|
67
|
+
- When FAB response with something other than 2xx status code, the response
|
68
|
+
contains an error array with a `PartnerApi::Errors::RequestError`
|
69
|
+
|
70
|
+
- When FAB response with 2xx status code and result is failure, the response
|
71
|
+
contains an error array with all errors mapped to `PartnerApi::Errors::RequestError`
|
72
|
+
|
73
|
+
Below is an example of error handling:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
begin
|
77
|
+
response = FabApi::Client.new.deliver_email(
|
78
|
+
partner_user_id: '8000000',
|
79
|
+
notification_id: SecureRandom.uuid,
|
80
|
+
subject: 'some subject',
|
81
|
+
message: 'this is an email'
|
82
|
+
)
|
83
|
+
|
84
|
+
if response.success?
|
85
|
+
# handle success response
|
86
|
+
else
|
87
|
+
if response.failure.status.success?
|
88
|
+
|
89
|
+
# handle errors based on error code
|
90
|
+
response.failure.errors.map do |error|
|
91
|
+
puts error.code
|
92
|
+
puts error.message
|
93
|
+
end
|
94
|
+
else
|
95
|
+
|
96
|
+
# handle general failure
|
97
|
+
raise response.failure.error
|
98
|
+
# or
|
99
|
+
# puts response.failure.errors.first.body
|
100
|
+
#
|
101
|
+
# or handle original response body
|
102
|
+
# puts response.failure.body
|
103
|
+
end
|
104
|
+
end
|
105
|
+
rescue PartnerApi::Errors::ConnectionError => e
|
106
|
+
# handle correction error
|
107
|
+
log(e)
|
108
|
+
raise e
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
---
|
113
|
+
|
114
|
+
## Endpoints
|
115
|
+
|
116
|
+
### Deliver Email
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
response = FabApi::Client.new.deliver_email(
|
120
|
+
partner_user_id: '8000000',
|
121
|
+
notification_id: SecureRandom.uuid,
|
122
|
+
subject: 'some subject',
|
123
|
+
message: 'this is an email'
|
124
|
+
)
|
125
|
+
|
126
|
+
if response.success?
|
127
|
+
# do something
|
128
|
+
else
|
129
|
+
# handle error
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
### Deliver SMS
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
response = FabApi::Client.new.deliver_sms(
|
137
|
+
partner_user_id: '8000000',
|
138
|
+
notification_id: SecureRandom.uuid,
|
139
|
+
message: 'this is an sms'
|
140
|
+
)
|
141
|
+
|
142
|
+
if response.success?
|
143
|
+
# do something
|
144
|
+
else
|
145
|
+
# handle error
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
### Exchange access token for OAuth token
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
response = FabApi::Client.new.exchange_token(
|
153
|
+
access_token: 'ABC12345',
|
154
|
+
transaction_id: SecureRandom.uuid,
|
155
|
+
system: 'RIB'
|
156
|
+
)
|
157
|
+
|
158
|
+
if response.success?
|
159
|
+
puts response.value! # token
|
160
|
+
else
|
161
|
+
# handle error
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
### Fetch new OAuth token using refresh token
|
166
|
+
|
167
|
+
- About `new_token_flag`:
|
168
|
+
- If the value is `true`, FAB creates a new OAuth token with full expiration
|
169
|
+
time
|
170
|
+
- If the value is `false`, FAB fetches a cache token (if there are any) so the
|
171
|
+
token can have lower expiration time
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
response = FabApi::Client.new.refresh_token(
|
175
|
+
access_token: 'ABC12345',
|
176
|
+
refresh_token: 'XYZ98765',
|
177
|
+
transaction_id: SecureRandom.uuid,
|
178
|
+
system: 'RIB',
|
179
|
+
new_token_flag: true
|
180
|
+
)
|
181
|
+
|
182
|
+
if response.success?
|
183
|
+
puts response.value! # token
|
184
|
+
else
|
185
|
+
# handle error
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
### Invalidate access token and related OAuth token
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
response = FabApi::Client.new.invalidate_token(
|
195
|
+
partner_user_id: '8000000',
|
196
|
+
access_token: 'ABC12345',
|
197
|
+
transaction_id: SecureRandom.uuid,
|
198
|
+
system: 'RIB',
|
199
|
+
)
|
200
|
+
|
201
|
+
if response.success?
|
202
|
+
# handle success
|
203
|
+
else
|
204
|
+
# handle error
|
205
|
+
end
|
206
|
+
```
|
data/docs/gemini_api.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# GeminiApi Usage
|
2
|
+
|
3
|
+
- [GeminiApi Usage](#geminiapi-usage)
|
4
|
+
- [Configuration](#configuration)
|
5
|
+
- [Handle errors](#handle-errors)
|
6
|
+
- [Endpoints](#endpoints)
|
7
|
+
- [Create Address Request](#create-address-request)
|
8
|
+
- [View Approved Addresses](#view-approved-addresses)
|
9
|
+
- [Withdraw Crypto Fund](#withdraw-crypto-fund)
|
10
|
+
- [Get available balances](#get-available-balances)
|
11
|
+
- [View Transfers](#view-transfers)
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
GeminiApi.configure do |config|
|
17
|
+
config.logger = Logger.new # default: log to STDOUT, level info
|
18
|
+
|
19
|
+
config.base_url = 'https://api.gemini.com'
|
20
|
+
config.api_key = 'some_api_key'
|
21
|
+
config.api_secret = 'some_api_secret'
|
22
|
+
|
23
|
+
config.default_headers = -> lambda do
|
24
|
+
{ 'x-request-id' => Oculus::Core.context[:request_id] }
|
25
|
+
end
|
26
|
+
config.default_parameters = -> { {} }
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
---
|
31
|
+
|
32
|
+
## Handle errors
|
33
|
+
|
34
|
+
The client is consistent in error handling, this works accross all method calls:
|
35
|
+
|
36
|
+
- When there are connection errors, it raises `PartnerApi::Errors::ConnectionError`
|
37
|
+
|
38
|
+
- When Gemini responds with something other than 2xx status code, the response
|
39
|
+
contains an error array with a `PartnerApi::Errors::RequestError`
|
40
|
+
|
41
|
+
Below is an example of error handling:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
begin
|
45
|
+
response = GeminiApi::Client.new.view_approved_addresses(**params)
|
46
|
+
|
47
|
+
if response.success?
|
48
|
+
# handle success response
|
49
|
+
else
|
50
|
+
# handle general failure
|
51
|
+
raise response.failure.error
|
52
|
+
|
53
|
+
# or handle original response body
|
54
|
+
# puts response.failure.body
|
55
|
+
end
|
56
|
+
rescue PartnerApi::Errors::ConnectionError => e
|
57
|
+
# handle correction error
|
58
|
+
log(e)
|
59
|
+
raise e
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
---
|
64
|
+
|
65
|
+
## Endpoints
|
66
|
+
|
67
|
+
### Create Address Request
|
68
|
+
|
69
|
+
Gemini docs: https://docs.gemini.com/rest-api/#create-an-address-request
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
response = GeminiApi::Client.new.create_address_request(
|
73
|
+
network: 'gusd',
|
74
|
+
address: '0xDe68f2E91f3AbCca99c35c2330b8A0a32de81150',
|
75
|
+
label: 'test_account',
|
76
|
+
account: 'primary' # optional
|
77
|
+
)
|
78
|
+
|
79
|
+
if response.success?
|
80
|
+
# handle successful case
|
81
|
+
else
|
82
|
+
# get the error from the failure object
|
83
|
+
puts response.failure
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### View approved addresses
|
88
|
+
|
89
|
+
Gemini docs: https://docs.gemini.com/rest-api/#view-approved-addresses
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
response = GeminiApi::Client.new.view_approved_addresses(
|
93
|
+
network: 'gusd',
|
94
|
+
account: 'primary'
|
95
|
+
)
|
96
|
+
|
97
|
+
if response.success?
|
98
|
+
addresses = response.value!
|
99
|
+
|
100
|
+
addresses.each do |address|
|
101
|
+
puts address.network # => 'etherium'
|
102
|
+
puts address.status # => 'pending-time'
|
103
|
+
puts address.address # => '0x.....12345'
|
104
|
+
end
|
105
|
+
else
|
106
|
+
# get the error from the failure object
|
107
|
+
puts response.failure
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
### Withdraw crypto fund
|
112
|
+
|
113
|
+
Gemini docs:
|
114
|
+
- Withdraw GUSD: https://docs.gemini.com/rest-api/#withdraw-usd-as-gusd
|
115
|
+
- Withdraw other currency: https://docs.gemini.com/rest-api/#withdraw-crypto-funds
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
response = GeminiApi::Client.new.withdraw_crypto_fund(
|
119
|
+
network: 'gusd',
|
120
|
+
amount: 0.1,
|
121
|
+
account: 'primary',
|
122
|
+
address: '0x....1234'
|
123
|
+
)
|
124
|
+
|
125
|
+
if response.success?
|
126
|
+
transaction = response.value!
|
127
|
+
|
128
|
+
puts transaction.id # => '62903dc2-ba64-48e9-9121-c648fa59353b'
|
129
|
+
puts transaction.amount # => 0.1
|
130
|
+
puts transaction.address # => '0x....1234'
|
131
|
+
else
|
132
|
+
# get the error from the failure object
|
133
|
+
puts response.failure
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
### Get available balances
|
138
|
+
|
139
|
+
Gemini docs: https://docs.gemini.com/rest-api/#get-available-balances
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
response = GeminiApi::Client.new.get_available_balances(account: 'primary')
|
143
|
+
|
144
|
+
if response.success?
|
145
|
+
balances = response.value!
|
146
|
+
|
147
|
+
balances.each do |balance|
|
148
|
+
puts balance.currency # => 'USD'
|
149
|
+
puts balance.amount # => 10000.0
|
150
|
+
puts balance.available_for_withdrawal # => 8000.0
|
151
|
+
end
|
152
|
+
else
|
153
|
+
# get the error from the failure object
|
154
|
+
puts response.failure
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
### View transfers
|
159
|
+
|
160
|
+
Gemini docs: https://docs.gemini.com/rest-api/#transfers
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
response = GeminiApi::Client.new.view_transfers(
|
164
|
+
currency: 'gusd',
|
165
|
+
timestamp: 1669626639000,
|
166
|
+
limit_transfers: 50,
|
167
|
+
account: 'primary',
|
168
|
+
show_completed_deposit_advances: false
|
169
|
+
)
|
170
|
+
|
171
|
+
if response.success?
|
172
|
+
transfers = response.value!
|
173
|
+
|
174
|
+
transfers.each do |transfer|
|
175
|
+
puts balance.type # => 'Withdrawal'
|
176
|
+
puts balance.status # => 'Completed'
|
177
|
+
puts balance.amount # => '10.0'
|
178
|
+
# ... and more
|
179
|
+
end
|
180
|
+
else
|
181
|
+
# get the error from the failure object
|
182
|
+
puts response.failure
|
183
|
+
end
|
184
|
+
```
|
data/docs/vma_api.md
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
# VmaApi Usage
|
2
|
+
|
3
|
+
* [Configuration](#configuration)
|
4
|
+
* [Handle errors](#handle-errors)
|
5
|
+
* Endpoints
|
6
|
+
* [Exchange short token with access token](#exchange-short-token-with-access-token)
|
7
|
+
* [Refresh access token with refresh-token](#refresh-access-token-with-refresh-token)
|
8
|
+
* [Get client credentials auth token](#get-client-credentials-auth-token)
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
VmaApi.configure do |config|
|
14
|
+
config.logger = Logger.new # default: log to STDOUT, level info
|
15
|
+
|
16
|
+
# Use this for accessing CIAM access token endpoints, etc.
|
17
|
+
config.auth_base_url = 'http://auth.vma.au'
|
18
|
+
config.auth_client_id = 'vma-issued-auth-client-id'
|
19
|
+
config.auth_client_secret = 'vma-issued-auth-client-secret'
|
20
|
+
|
21
|
+
config.base_url = 'http://www.vma.au'
|
22
|
+
# Configure credentials for making calls to VMA API
|
23
|
+
config.client_id = 'vma-issued-client-id'
|
24
|
+
config.client_secret = 'vma-issued-client-secret'
|
25
|
+
|
26
|
+
# Needed for headers construction during token exchange and token refresh
|
27
|
+
config.subscription_key = 'subscription-key'
|
28
|
+
config.system_id = 'Guardhouse'
|
29
|
+
|
30
|
+
# by default, it sets all request params to include client_id and client_secret
|
31
|
+
config.default_parameters = -> {
|
32
|
+
{
|
33
|
+
"client_id": config.client_id,
|
34
|
+
"client_secret": config.client_secret
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
# by default, it sets content-type as json
|
39
|
+
config.default_headers = -> {
|
40
|
+
{ 'Content-Type' => 'application/json' }
|
41
|
+
}
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
We can also configure on-the-fly using `Configuration` class:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
config = VmaApi::Configuration.new.configure do |c|
|
49
|
+
c.client_id = 'vma-issued-client-id'
|
50
|
+
c.client_secret = 'vma-issued-client-secret'
|
51
|
+
end
|
52
|
+
|
53
|
+
client = VmaApi::Client.new(config.config)
|
54
|
+
```
|
55
|
+
|
56
|
+
---
|
57
|
+
|
58
|
+
## Handle errors
|
59
|
+
|
60
|
+
The client is consistent in error handling, this works accross all method calls:
|
61
|
+
|
62
|
+
- When there are connection errors, it raises `PartnerApi::Errors::ConnectionError`
|
63
|
+
|
64
|
+
- When VMA responds with something other than 2xx status code, the response
|
65
|
+
contains an error array with a `PartnerApi::Errors::RequestError`
|
66
|
+
|
67
|
+
Below is an example of error handling:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
begin
|
71
|
+
response = VmaApi::Client.new.access_token(short_token: 'token')
|
72
|
+
|
73
|
+
if response.success?
|
74
|
+
# handle success response
|
75
|
+
else
|
76
|
+
if response.failure.status.success?
|
77
|
+
|
78
|
+
# handle errors based on error code
|
79
|
+
response.failure.errors.map do |error|
|
80
|
+
puts error.code
|
81
|
+
puts error.message
|
82
|
+
end
|
83
|
+
else
|
84
|
+
|
85
|
+
# handle general failure
|
86
|
+
raise response.failure.error
|
87
|
+
# or
|
88
|
+
# puts response.failure.errors.first.body
|
89
|
+
#
|
90
|
+
# or handle original response body
|
91
|
+
# puts response.failure.body
|
92
|
+
end
|
93
|
+
end
|
94
|
+
rescue PartnerApi::Errors::ConnectionError => e
|
95
|
+
# handle correction error
|
96
|
+
log(e)
|
97
|
+
raise e
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
---
|
102
|
+
|
103
|
+
## Endpoints
|
104
|
+
|
105
|
+
### Exchange short token with access token
|
106
|
+
|
107
|
+
Make sure you set the settings `auth_base_url`, `auth_client_id` and `auth_client_secret`.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
response = VmaApi::Client.new.access_token(short_token: 'your-short-token')
|
111
|
+
|
112
|
+
if response.success?
|
113
|
+
# decrypt the token using the JWE secret
|
114
|
+
decrypt(response.value!)
|
115
|
+
else
|
116
|
+
# get the error from the failure object
|
117
|
+
puts response.failure
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
### Refresh access token with refresh token
|
122
|
+
|
123
|
+
Make sure you set the settings `auth_base_url`, `auth_client_id` and `auth_client_secret`.
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
response = VmaApi::Client.new.refresh_token(refresh_token: 'your-refresh-token')
|
127
|
+
|
128
|
+
if response.success?
|
129
|
+
# decrypt the token using the JWE secret
|
130
|
+
decrypt(response.value!)
|
131
|
+
else
|
132
|
+
# get the error from the failure object
|
133
|
+
puts response.failure
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
### Get client credentials auth token
|
138
|
+
|
139
|
+
Make sure you set the settings `base_url`, `client_id` and `client_secret`.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
response = VmaApi::Client.new.client_credentials(
|
143
|
+
tenant_id: '8888-8888-8888-88',
|
144
|
+
resource: 'CIAM://resource-id'
|
145
|
+
)
|
146
|
+
|
147
|
+
if response.success?
|
148
|
+
puts response.value! # token
|
149
|
+
else
|
150
|
+
# get the error from the failure object
|
151
|
+
puts response.failure
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
### Invalidate access token and related OAuth token
|
156
|
+
|
157
|
+
Make sure you set the settings `auth_base_url`, `auth_client_id` and `auth_client_secret`.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
response = VmaApi::Client.new.revoke_token(token: 'token')
|
161
|
+
|
162
|
+
if response.success?
|
163
|
+
# handle success
|
164
|
+
else
|
165
|
+
# handle error
|
166
|
+
end
|
167
|
+
```
|
data/docs/westpac_api.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# WestpacApi Usage
|
2
|
+
|
3
|
+
* [Configuration](#configuration)
|
4
|
+
* [Handle errors](#handle-errors)
|
5
|
+
* Endpoints
|
6
|
+
* [Fetch JWKS](#fetch-jwks)
|
7
|
+
* [Fetch User Info](#fetch-user-info)
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
WestpacApi.configure do |config|
|
13
|
+
config.logger = Logger.new # default: log to STDOUT, level info
|
14
|
+
|
15
|
+
# URL for fetching JWK
|
16
|
+
config.jwk_url = 'http://www.westpac.au/jwks'
|
17
|
+
|
18
|
+
# URL for fetching user info
|
19
|
+
config.context_api.url = 'https://gw-partner.sit1.api.westpac.com.au/ptr/partner/vendor/westpac/ctxthndvrascenda/v1/ascendaContext'
|
20
|
+
|
21
|
+
# Those values are in 1Password Westpac context API basic auth
|
22
|
+
config.context_api.username = 'username'
|
23
|
+
config.context_api.password = 'password'
|
24
|
+
|
25
|
+
# Proxy is optional. Only needed if when setting up local environment.
|
26
|
+
config.context_api.proxy_address = 'proxy.int.kaligo.com'
|
27
|
+
config.context_api.proxy_port = '3128'
|
28
|
+
|
29
|
+
config.context_api.public_key = 'somecert'
|
30
|
+
config.context_api.private_key = 'somekey'
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
## Handle errors
|
37
|
+
|
38
|
+
The client is consistent in error handling, this works accross all method calls:
|
39
|
+
|
40
|
+
- When there are connection errors, it raises `PartnerApi::Errors::ConnectionError`
|
41
|
+
|
42
|
+
- When VMA responds with something other than 2xx status code, the response
|
43
|
+
contains an error array with a `PartnerApi::Errors::RequestError`
|
44
|
+
|
45
|
+
Below is an example of error handling:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
begin
|
49
|
+
response = WestpacApi::Client.new.fetch_jwk
|
50
|
+
|
51
|
+
if response.success?
|
52
|
+
# handle success response
|
53
|
+
else
|
54
|
+
# handle general failure
|
55
|
+
raise response.failure.error
|
56
|
+
|
57
|
+
# or handle original response body
|
58
|
+
# puts response.failure.body
|
59
|
+
end
|
60
|
+
rescue PartnerApi::Errors::ConnectionError => e
|
61
|
+
# handle correction error
|
62
|
+
log(e)
|
63
|
+
raise e
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
## Endpoints
|
70
|
+
|
71
|
+
### Fetch JWKS
|
72
|
+
|
73
|
+
Make sure you set the settings `jwk_url`
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
response = WestpacApi::Client.new.fetch_jwk
|
77
|
+
|
78
|
+
if response.success?
|
79
|
+
# handle response
|
80
|
+
puts response.value!
|
81
|
+
else
|
82
|
+
# get the error from the failure object
|
83
|
+
puts response.failure
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### Fetch User Info
|
88
|
+
|
89
|
+
Westpac context endpoint requires basic authentication, with proxy and ssl certificates enable.
|
90
|
+
|
91
|
+
Make sure you set the settings `context_url`, `username`, `password`, `proxy_address`, `proxy_port`, `public_key`, `private_key`
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
response = WestpacApi::Client.new.fetch_user(
|
95
|
+
user_id: sub,
|
96
|
+
context_reference_id: ctxrefid
|
97
|
+
)
|
98
|
+
|
99
|
+
if response.success?
|
100
|
+
# handle response
|
101
|
+
puts response.value!
|
102
|
+
else
|
103
|
+
# get the error from the failure object
|
104
|
+
puts response.failure
|
105
|
+
end
|
106
|
+
```
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'anz_api/endpoints/fetch_jwk'
|
2
|
+
|
3
|
+
module AnzApi
|
4
|
+
class Client
|
5
|
+
def self.endpoint(name)
|
6
|
+
define_method(name) do |**args|
|
7
|
+
klass_name = Hanami::Utils::String.classify(name)
|
8
|
+
endpoint_klass = Hanami::Utils::Class.load!("AnzApi::Endpoints::#{klass_name}")
|
9
|
+
|
10
|
+
endpoint_klass.(config, **args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
endpoint :fetch_jwk
|
15
|
+
|
16
|
+
def initialize(config: AnzApi.config)
|
17
|
+
@config = config
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :config
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'partner_api/endpoints/base'
|
2
|
+
require 'anz_api/failure_response'
|
3
|
+
|
4
|
+
module AnzApi
|
5
|
+
class Endpoint < PartnerApi::Endpoints::Base
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection_options
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
|
13
|
+
def decode(response)
|
14
|
+
response.parse
|
15
|
+
end
|
16
|
+
|
17
|
+
def successful?(response)
|
18
|
+
response.status.success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def decode_error(response)
|
22
|
+
FailureResponse.new(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def logging_params
|
26
|
+
{ request_id: request_id }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|