nedbank_api 0.2.2 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 232191d832adf52be4ec8b3819395c3624a33d57
4
- data.tar.gz: 1963075ba078b1d5327ad81991767daac2a472cd
3
+ metadata.gz: 6fb9117ddc2c8216ec72760a551d41982c267fd1
4
+ data.tar.gz: 242312db170605559aec9b75e24755d8485e4dd8
5
5
  SHA512:
6
- metadata.gz: 0d1264a544ff92c7d3557428b15084a43f6b5441ebcbaf7452ee1afa66786c615cfa7975ff5ca8aea62e63c78a21b0c83f2b3af2e2bdd214f928c1cb4f0648fa
7
- data.tar.gz: 678d7a4f9d708e93cc57300c86b06675e7e3a12f5f723d9c77798467b148c139e8653d9fcead30a6f8ba0d76e05943e78b1d606e43db0360e90bf53a4daeb4e9
6
+ metadata.gz: 46ce862d9507e3f3f261557295d0f4586145145b87a004c196eb5efb220dee39cef4b486ac1ba8288a1e34bff5f5f6768dc16fe2f0807367cbbee3a1c6a27ffc
7
+ data.tar.gz: 0ddb5f94ddfe19a3d2287821781cecb05acc25cdd3fa17ccf17afa7e1b43a637c879e3e6c5308c0ccd76c1a32729ca645801d6bcf398752f4db1695590be4235
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nedbank_api (0.2.2)
4
+ nedbank_api (0.2.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # NedbankApi
1
+ # Nedbank API
2
2
 
3
3
  The purpose of this gem is to streamline development of a Ruby application when using the [Nedbank Marketplace API](https://apim.nedbank.co.za/static/docs).
4
4
 
@@ -9,7 +9,7 @@ This gem currently only uses the Authoristaions API and Payments API. If you are
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'nedbank_api', github: 'jono-booth/nedbank_api'
12
+ gem 'nedbank_api'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -18,8 +18,6 @@ require 'uri'
18
18
  require 'securerandom'
19
19
 
20
20
  module NedbankApi
21
- @intent_token = Models::IntentToken.new(Object.new)
22
-
23
21
  class << self
24
22
  attr_accessor :intent_token,
25
23
  :configuration
@@ -1,10 +1,6 @@
1
1
  module NedbankApi
2
2
  class ApiWrapper
3
3
  class << self
4
- def idempotency_key
5
- rand.to_s[2..24]
6
- end
7
-
8
4
  def auth_headers(overrides={})
9
5
  {
10
6
  "Content-Type" => "application/json",
@@ -17,8 +13,12 @@ module NedbankApi
17
13
  }.merge(overrides)
18
14
  end
19
15
 
20
- def endpoint(path)
21
- NedbankApi.configuration.api_endpoint + path
16
+ def idempotency_key
17
+ rand.to_s[2..24]
18
+ end
19
+
20
+ def endpoint(path, suffix: nil)
21
+ [NedbankApi.configuration.api_endpoint, path, suffix].compact.join('/')
22
22
  end
23
23
 
24
24
  def json_to_object(json)
@@ -1,8 +1,13 @@
1
1
  module NedbankApi
2
2
  class AuthenticationsApi < ApiWrapper
3
3
  class << self
4
+ API_PATHS = {
5
+ request_token: 'nboauth/oauth20/token',
6
+ authorise: 'nboauth/oauth20/authorize'
7
+ }
8
+
4
9
  def request_token_light
5
- http = Http.new(url: endpoint('/nboauth/oauth20/token'))
10
+ http = Http.new(url: endpoint(API_PATHS[:request_token]))
6
11
 
7
12
  response = http.post(
8
13
  body: URI.encode_www_form({
@@ -21,7 +26,7 @@ module NedbankApi
21
26
  end
22
27
 
23
28
  def request_token_heavy(request_body: {})
24
- http = Http.new(url: endpoint('/nboauth/oauth20/token'))
29
+ http = Http.new(url: endpoint(API_PATHS[:request_token]))
25
30
 
26
31
  response = http.post(
27
32
  body: URI.encode_www_form({
@@ -40,7 +45,7 @@ module NedbankApi
40
45
  end
41
46
 
42
47
  def authorisation_url(request_body: {})
43
- url = endpoint('/nboauth/oauth20/authorize')
48
+ url = endpoint(API_PATHS[:authorise])
44
49
 
45
50
  body = URI.encode_www_form({
46
51
  client_id: NedbankApi.configuration.client_id,
@@ -1,8 +1,14 @@
1
1
  module NedbankApi
2
2
  class PaymentsApi < ApiWrapper
3
3
  class << self
4
- def create_intent(request_body: {})
5
- http = Http.new(url: endpoint('/open-banking/payments'))
4
+
5
+ API_PATHS = {
6
+ payments: 'open-banking/payments',
7
+ payment_submissions: 'open-banking/payment-submissions'
8
+ }
9
+
10
+ def create_intent(request_body: {}, headers: {})
11
+ http = Http.new(url: endpoint(API_PATHS[:payments]))
6
12
 
7
13
  response = http.post(
8
14
  headers: auth_headers,
@@ -12,8 +18,8 @@ module NedbankApi
12
18
  return Models::Payment.new(json_to_object(response.body))
13
19
  end
14
20
 
15
- def submit_payment(request_body: {})
16
- http = Http.new(url: endpoint('/open-banking/payment-submissions'))
21
+ def submit_payment(request_body: {}, headers: {})
22
+ http = Http.new(url: endpoint(API_PATHS[:payment_submissions]))
17
23
 
18
24
  response = http.post(
19
25
  headers: auth_headers,
@@ -23,8 +29,8 @@ module NedbankApi
23
29
  return Models::PaymentSubmission.new(json_to_object(response.body))
24
30
  end
25
31
 
26
- def get_payment_submission(payment_submission_id:)
27
- http = Http.new(url: endpoint('/open-banking/payment-submissions/' + payment_submission_id))
32
+ def get_payment_submission(payment_submission_id:, headers: {})
33
+ http = Http.new(url: endpoint(API_PATHS[:payment_submissions], suffix: payment_submission_id))
28
34
 
29
35
  response = http.get(
30
36
  headers: auth_headers
@@ -4,36 +4,33 @@ module NedbankApi
4
4
  @url = URI(url)
5
5
  end
6
6
 
7
- def net_http
8
- @net_http ||= Net::HTTP.new(@url.host, @url.port).tap do |http|
9
- http.use_ssl = true
10
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
11
- end
12
- end
13
-
14
7
  def get(body: {}, headers: {})
15
8
  request = Net::HTTP::Get.new(@url)
16
-
17
- headers.each do |key,value|
18
- request[key] = value
19
- end
20
-
21
- request.body = body
22
- response = net_http.request(request)
23
-
24
- return response
9
+ make_request(request: request, body: body, headers: headers)
25
10
  end
11
+
26
12
  def post(body: {}, headers: {})
27
13
  request = Net::HTTP::Post.new(@url)
14
+ make_request(request: request, body: body, headers: headers)
15
+ end
28
16
 
17
+ def make_request(request:, body: {}, headers: {})
29
18
  headers.each do |key,value|
30
19
  request[key] = value
31
20
  end
32
21
 
33
22
  request.body = body
34
- response = net_http.request(request)
23
+ net_http.request(request)
24
+ end
25
+
26
+ private
35
27
 
36
- return response
28
+ def net_http
29
+ @net_http ||= Net::HTTP.new(@url.host, @url.port).tap do |http|
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
32
+ end
37
33
  end
34
+
38
35
  end
39
36
  end
@@ -1,3 +1,3 @@
1
1
  module NedbankApi
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.email = 'jonobth@gmail.com'
14
14
  s.metadata = { 'source_code_uri' => 'https://github.com/jono-booth/nedbank_api' }
15
15
 
16
- s.files = `git ls-files -z`.split("\x0")
16
+ s.files = `git ls-files -z`.split("\x0").reject{ |f| f.end_with? '.gem' }
17
17
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  s.test_files = s.files.grep(%r{^spec/})
19
19
  s.require_paths = ['lib']
@@ -1,4 +1,8 @@
1
1
  RSpec.describe NedbankApi::PaymentsApi do
2
+ before :each do
3
+ NedbankApi.intent_token = build(:fake_client)
4
+ end
5
+
2
6
  describe '.create_intent' do
3
7
  let(:request_body) { File.read('spec/support/payment/post_intent_request.json') }
4
8
  let(:response_body) { File.read('spec/support/payment/post_intent_response.json') }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nedbank_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jono Booth