viva_wallet 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: df88fd51bb67f6281953a1fde24d80512ccce512a28cac820f50ce4b2f4d7e07
4
- data.tar.gz: 96f85abf2115cd2c87afbd37bff8113ec7a5ce9c737acc1a6a5d203129dbeea1
3
+ metadata.gz: 4e68c84d09bee7cede06b0fc0d675c1e8eeaa982f43a627c1187c9a09b87a8e7
4
+ data.tar.gz: e7f1eca90376323db9c3b7b6d213b29071766ec001a1337cb20adacaa5e8adcb
5
5
  SHA512:
6
- metadata.gz: e5528585913c86f6efb7d4941a673c0af6f10e80c93eff5d8adc51aa83488517385a13ea53929067fcffb681769c62b6b413a03f5d9fc6dc1922ccf7880f208d
7
- data.tar.gz: f602904f1d2c92db35d1451611548f567217481bb8b4509cd390ed7671ff5307c9a077c9fc9e8a665ff01e29c6eb4c053aa4bf56726b5100e07d1678c1931e8d
6
+ metadata.gz: 34958e461194cb8d787305af0152584146059bbff657314ad454f741180d60f60cc34f424053d4cd2dcfe5fb25ee2fe7d75a329f1f81e8b133ac589e01d1a9b9
7
+ data.tar.gz: 24fb1e3875c691e36ac3d24469d0469a764863dd6c715330c6008860803200eede7b35bfcb9b975067ba99fdaca2c237ea9bb1dea92a66a003182e413617137e
data/README.md CHANGED
@@ -22,8 +22,8 @@ Set up an initializer file with your Viva Wallet Smart Checkout client keys:
22
22
 
23
23
  ```ruby
24
24
  VivaWallet.client_id = 'viva_client_id'
25
- VivaWallet.client_secret = 'v1'
26
- VivaWallet.test_mode = "true or false"
25
+ VivaWallet.client_secret = 'viva_client_secret'
26
+ VivaWallet.test_mode = true/false
27
27
  ```
28
28
  e.g. *config/initializers/viva_wallet.rb*
29
29
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VivaWallet
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/viva_wallet.rb CHANGED
@@ -9,78 +9,79 @@ require_relative 'viva_wallet/payment'
9
9
 
10
10
  module VivaWallet
11
11
 
12
- class VivaWalletError < StandardError
13
- end
12
+ class VivaWalletError < StandardError; end
14
13
 
15
14
  class ConfigurationError < VivaWalletError; end
16
15
 
17
- attr_writer :client_id, :client_secret, :test_mode, :api_base, :account_api_base, :client_base64
18
-
19
- def client_id
20
- defined? @client_id and @client_id or raise(
21
- ConfigurationError, "VivaWallet client_id not configured"
22
- )
23
- end
16
+ class << self
17
+ attr_writer :client_id, :client_secret, :test_mode, :api_base, :account_api_base, :client_base64
24
18
 
25
- def client_secret
26
- defined? @client_secret and @client_secret or raise(
27
- ConfigurationError, "VivaWallet client_secret not configured"
28
- )
29
- end
19
+ def client_id
20
+ defined? @client_id and @client_id or raise(
21
+ ConfigurationError, "VivaWallet client_id not configured"
22
+ )
23
+ end
30
24
 
31
- def test_mode
32
- @test_mode.nil? ? false : @test_mode
33
- end
25
+ def client_secret
26
+ defined? @client_secret and @client_secret or raise(
27
+ ConfigurationError, "VivaWallet client_secret not configured"
28
+ )
29
+ end
34
30
 
35
- def api_base
36
- VivaWallet.test_mode ? "https://demo-api.vivapayments.com/" : "https://api.vivapayments.com/"
37
- end
31
+ def test_mode
32
+ @test_mode.nil? ? false : @test_mode
33
+ end
38
34
 
39
- def account_api_base
40
- VivaWallet.test_mode ? "https://demo-accounts.vivapayments.com/" : "https://accounts.vivapayments.com/"
41
- end
35
+ def api_base
36
+ VivaWallet.test_mode ? "https://demo-api.vivapayments.com/" : "https://api.vivapayments.com/"
37
+ end
42
38
 
43
- def client_base64
44
- Base64.encode("#{VivaWallet.client_id}:#{VivaWallet.client_secret}")
45
- end
39
+ def account_api_base
40
+ VivaWallet.test_mode ? "https://demo-accounts.vivapayments.com/" : "https://accounts.vivapayments.com/"
41
+ end
46
42
 
47
- def request(method, resource, params = {}, access_token = nil)
48
- access_token = access_token
49
-
50
- params.except!(:access_token)
51
-
52
- defined? method or raise(
53
- ArgumentError, "Request method has not been specified"
54
- )
55
- defined? resource or raise(
56
- ArgumentError, "Request resource has not been specified"
57
- )
58
-
59
- if method == :get
60
- url = VivaWallet.api_base + resource + '?' + params
61
- headers = {
62
- accept: :json,
63
- content_type: :json,
64
- 'Authorization': "Bearer #{access_token}"
65
- }.merge({ params: params })
66
- payload = nil
67
- else
68
- url = VivaWallet.api_base + resource
69
- headers = {
70
- accept: :json,
71
- content_type: :json,
72
- 'Authorization': "Bearer #{access_token}"
73
- }
74
- payload = params
43
+ def client_base64
44
+ Base64.encode("#{VivaWallet.client_id}:#{VivaWallet.client_secret}")
75
45
  end
76
- RestClient::Request.new({
77
- method: method,
78
- url: url,
79
- payload: payload.to_json,
80
- headers: headers
81
- }).execute do |response, request, result|
82
- str_response = response.to_str
83
- str_response.blank? ? '' : JSON.parse(str_response)
46
+
47
+ def request(method, resource, params = {}, access_token = nil)
48
+ access_token = access_token
49
+
50
+ params.except!(:access_token)
51
+
52
+ defined? method or raise(
53
+ ArgumentError, "Request method has not been specified"
54
+ )
55
+ defined? resource or raise(
56
+ ArgumentError, "Request resource has not been specified"
57
+ )
58
+
59
+ if method == :get
60
+ url = VivaWallet.api_base + resource + '?' + params
61
+ headers = {
62
+ accept: :json,
63
+ content_type: :json,
64
+ 'Authorization': "Bearer #{access_token}"
65
+ }.merge({ params: params })
66
+ payload = nil
67
+ else
68
+ url = VivaWallet.api_base + resource
69
+ headers = {
70
+ accept: :json,
71
+ content_type: :json,
72
+ 'Authorization': "Bearer #{access_token}"
73
+ }
74
+ payload = params
75
+ end
76
+ RestClient::Request.new({
77
+ method: method,
78
+ url: url,
79
+ payload: payload.to_json,
80
+ headers: headers
81
+ }).execute do |response, request, result|
82
+ str_response = response.to_str
83
+ str_response.blank? ? '' : JSON.parse(str_response)
84
+ end
84
85
  end
85
86
  end
86
87
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viva_wallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Dallimore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-08 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client