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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7cacf04c0842fae66017e82f8ac66c80c457516055b9e06f7e44c16303d32327
4
+ data.tar.gz: e9b46531becb170f52959334ca4c8f968a955efb9c34e7450354001adf77fee1
5
+ SHA512:
6
+ metadata.gz: e9502db4c374e70a24a707c0b8c1a5301eb435928208b276fea6b3513e91004406655675c68037d35cb9779aa24a5740544fcbbb0ecdb3bfbc1221cf4fcaef85
7
+ data.tar.gz: 8213446b7663bf6113cb49007d6a293bc5f883bc8181e30060cd73d54ef8e88df92965b06a549b04598fdce0eb794ce4eb670354fd44a4d715dd0a37fd52b845
@@ -0,0 +1,18 @@
1
+ name: Release gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Build and publish gem
15
+ uses: jstastny/publish-gem-to-github@master
16
+ with:
17
+ token: ${{ secrets.WORKFLOW_TOKEN }}
18
+ owner: kaligo
@@ -0,0 +1,28 @@
1
+ name: RSpec
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby:
13
+ - "3.0"
14
+ - "2.6"
15
+ - "2.7"
16
+
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+
21
+ - uses: ruby/setup-ruby@v1
22
+ id: ruby
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+
27
+ - name: run rspec
28
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/bundle
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ Gemfile.lock
15
+ .ruby-version
16
+ .ruby-gemset
17
+
18
+ .idea
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --warnings
data/CHANGELOG.md ADDED
@@ -0,0 +1,105 @@
1
+ # Change Log
2
+
3
+ ## 0.11.2
4
+
5
+ - Support HTTP persistent for BNZ client
6
+
7
+ ## 0.11.1
8
+
9
+ - Emit metrics on Endpoint calls.
10
+
11
+ ## 0.11.0
12
+
13
+ - Allow to configure BnzApi configuration on the fly
14
+
15
+ ## 0.10.0
16
+
17
+ - Allow to have multiple FabApi configuration instances
18
+
19
+ ## 0.9.3
20
+
21
+ - Rescue OpenSSL::SSL::SSLError and re-raised as ConnectionError
22
+
23
+ ## 0.9.2
24
+
25
+ - Allow working with dry-configuration 1.x
26
+
27
+ ## 0.9.1
28
+
29
+ - Add view transfers endpoint to Gemini API
30
+
31
+ ## 0.9.0
32
+
33
+ - Update Westpac API to support `issuer` based configuration
34
+
35
+ ## 0.8.2
36
+
37
+ - Fix response for Gemini get balances endpoint
38
+
39
+ ## 0.8.1
40
+
41
+ - Add get balances endpoint to Gemini API
42
+
43
+ ## 0.8.0
44
+
45
+ - Add Gemini API
46
+
47
+ ## 0.7.4
48
+
49
+ - Expose response's headers
50
+
51
+ ## 0.7.1 Update BNZ API
52
+
53
+ - Add MTLS for id token endpoint
54
+ - Add JWKS endpoint
55
+ - Remove user info endpoint
56
+
57
+ ## 0.7 Add BNZ API
58
+
59
+ - Fetch id token endpoint
60
+ - Fetch user info
61
+
62
+ ## 0.6
63
+
64
+ - Use `default` keyword of new dry-configurable
65
+ - Require dry-configurable 0.13
66
+
67
+ ## 0.5
68
+
69
+ - Update Content-Type for FAB
70
+ - Require http-rb 5.x
71
+
72
+ ## 0.4.2
73
+
74
+ - Add log for request_id/transaction_id/correlation_id
75
+
76
+ ## 0.4.1 Add Westpac User Info endpoint
77
+
78
+ ## 0.4.0 Add Westpac JWK endpoint
79
+
80
+ ## 0.3.4 Support multiple connections for VMA
81
+
82
+ ## 0.3.3 Bug fixes:
83
+
84
+ - Fix request body sent during VMA client credentials call
85
+ - Separate URLs and credential configs for client credential and SSO endpoints
86
+
87
+ ## 0.3.2 Add VMA client credentails call
88
+
89
+ ## 0.3.1 Add VMA token invalidation endpoint
90
+
91
+ ## 0.3.0 Add VMA API client
92
+
93
+ ## 0.2.1 Bug fixes
94
+
95
+ - Temporary fix to handle FAB invalid MIME type
96
+
97
+ ## 0.2.0 Switch gem name to `partner_api`
98
+
99
+ ## 0.1.1 Bug fixes:
100
+
101
+ - Fix setting proxy & ssl options
102
+
103
+ ## 0.1.0 Initial functionality
104
+
105
+ - Most of FAB endpoints
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fab_api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "webmock"
9
+ gem 'byebug'
10
+ gem 'timecop'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Hieu Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # PartnerAPI
2
+
3
+ An API client to connect to API provided by all Ascenda Partners:
4
+
5
+ - First Abu Dhabi Bank
6
+ - Virgin Money Australia
7
+ - Westpac
8
+ - Bank of New Zealand
9
+ - Gemini
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'partner_api', ascenda_private: 'kaligo/partner_api', tag: 'v0.9.3'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+ ## Usage
24
+
25
+ - [FabApi Usage](docs/fab_api.md)
26
+ - [VmaApi Usage](docs/vma_api.md)
27
+ - [WestpacApi Usage](docs/westpac_api.md)
28
+ - [BnzApi Usage](docs/bnz_api.md)
29
+ - [Gemini Usage](docs/gemini_api.md)
30
+ - [Anz Usage](docs/anz_api.md)
31
+
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ### Add new endpoint
40
+
41
+ - Add endpoint into `FabApi::Client`:
42
+
43
+ ```ruby
44
+ module FabApi
45
+ class Client
46
+ endpoint :new_endpoint
47
+ end
48
+ end
49
+ ```
50
+
51
+ - Create new endpoint class. By convention, the class is put in
52
+ `lib/fab_api/endpoints` folder, and is inside module `FabApi::Endpoints`.
53
+ After creating the class, overwrite necessary methods to make the class work.
54
+ With the above example, the class should be:
55
+
56
+ ```ruby
57
+ module FabApi
58
+ module Endpoints
59
+ class NewEndpoint < Endpoint
60
+ prepend Initializer
61
+
62
+ def initialize(...)
63
+ # initializing thing
64
+ end
65
+
66
+ private
67
+
68
+ def method
69
+ # HTTP method
70
+ end
71
+
72
+ # ...
73
+ end
74
+ end
75
+ end
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kaligo/fab_api.
81
+
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bnz_api"
5
+ require "fab_api"
6
+ require "vma_api"
7
+ require "westpac_api"
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/docs/anz_api.md ADDED
@@ -0,0 +1,67 @@
1
+ # AnzApi Usage
2
+
3
+ - [AnzApi Usage](#anzapi-usage)
4
+ - [Configuration](#configuration)
5
+ - [Handle errors](#handle-errors)
6
+ - [Endpoints](#endpoints)
7
+ - [Fetch JWK](#fetch-jwk)
8
+
9
+ ## Configuration
10
+
11
+ ```ruby
12
+ AnzApi.configure do |config|
13
+ config.logger = Logger.new # default: log to STDOUT, level info
14
+ config.jwks_url = 'https://unauthib.anz.com/jwks'
15
+ end
16
+ ```
17
+
18
+ ---
19
+
20
+ ## Handle errors
21
+
22
+ The client is consistent in error handling, this works accross all method calls:
23
+
24
+ - When there are connection errors, it raises `PartnerApi::Errors::ConnectionError`
25
+
26
+ - When ANZ responds with something other than 2xx status code, the response
27
+ contains an error array with a `PartnerApi::Errors::RequestError`
28
+
29
+ Below is an example of error handling:
30
+
31
+ ```ruby
32
+ begin
33
+ response = AnzApi::Client.new.fetch_jwk
34
+
35
+ if response.success?
36
+ # handle success response
37
+ else
38
+ # handle general failure
39
+ raise response.failure.error
40
+
41
+ # or handle original response body
42
+ # puts response.failure.body
43
+ end
44
+ rescue PartnerApi::Errors::ConnectionError => e
45
+ # handle correction error
46
+ log(e)
47
+ raise e
48
+ end
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Endpoints
54
+
55
+ ### Fetch JWK
56
+
57
+ ```ruby
58
+ response = AnzApi::Client.new.fetch_jwk
59
+
60
+ if response.success?
61
+ # handle response
62
+ puts response.value!
63
+ else
64
+ # get the error from the failure object
65
+ puts response.failure
66
+ end
67
+ ```
data/docs/bnz_api.md ADDED
@@ -0,0 +1,103 @@
1
+ # BnzApi Usage
2
+
3
+ - [BnzApi Usage](#bnzapi-usage)
4
+ - [Configuration](#configuration)
5
+ - [Handle errors](#handle-errors)
6
+ - [Endpoints](#endpoints)
7
+ - [Fetch Id Token](#fetch-id-token)
8
+ - [Fetch JWK](#fetch-jwk)
9
+
10
+ ## Configuration
11
+
12
+ ```ruby
13
+ BnzApi.configure do |config|
14
+ config.logger = Logger.new # default: log to STDOUT, level info
15
+
16
+ config.token_url = 'https://ma.secure.bnz.co.nz/pingfederate/as/token.oauth2'
17
+ config.jwks_url = 'https://secure.bnz.co.nz/pingfederate/pf/JWKS'
18
+
19
+ # MTLS
20
+ config.token_exchange.public_key = 'public_key'
21
+ config.token_exchange.private_key = private_key'
22
+ end
23
+ ```
24
+ We can also configure on-the-fly using `Configuration` class:
25
+
26
+ ```ruby
27
+ config = BnzApi::Configuration.new.configure do |c|
28
+ c.token_exchange.public_key = 'new_cert'
29
+ c.token_exchange.private_key = 'new_key'
30
+ end
31
+
32
+ client = FabApi::Client.new(config: config)
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Handle errors
38
+
39
+ The client is consistent in error handling, this works accross all method calls:
40
+
41
+ - When there are connection errors, it raises `PartnerApi::Errors::ConnectionError`
42
+
43
+ - When BNZ responds with something other than 2xx status code, the response
44
+ contains an error array with a `PartnerApi::Errors::RequestError`
45
+
46
+ Below is an example of error handling:
47
+
48
+ ```ruby
49
+ begin
50
+ response = BnzApi::Client.new.fetch_id_token(**params)
51
+
52
+ if response.success?
53
+ # handle success response
54
+ else
55
+ # handle general failure
56
+ raise response.failure.error
57
+
58
+ # or handle original response body
59
+ # puts response.failure.body
60
+ end
61
+ rescue PartnerApi::Errors::ConnectionError => e
62
+ # handle correction error
63
+ log(e)
64
+ raise e
65
+ end
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Endpoints
71
+
72
+ ### Fetch Id Token
73
+
74
+ ```ruby
75
+ response = BnzApi::Client.new.fetch_id_token(
76
+ auth_code: auth_code,
77
+ redirect_uri: redirect_uri,
78
+ client_id: client_id,
79
+ request_id: request_id
80
+ )
81
+
82
+ if response.success?
83
+ # handle response
84
+ puts response.value!
85
+ else
86
+ # get the error from the failure object
87
+ puts response.failure
88
+ end
89
+ ```
90
+
91
+ ### Fetch JWK
92
+
93
+ ```ruby
94
+ response = BnzApi::Client.new.fetch_jwk
95
+
96
+ if response.success?
97
+ # handle response
98
+ puts response.value!
99
+ else
100
+ # get the error from the failure object
101
+ puts response.failure
102
+ end
103
+ ```