berbix 0.0.6 → 0.0.11

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/berbix.rb +49 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98b6319a50dfd32695ad42cc0052df8c7804c4b002c65764ba77ee4db4dc3096
4
- data.tar.gz: ac7ccb91f56cd327f1feee441e029e7cf8d340a1f38d16218ea53f104e4eb0db
3
+ metadata.gz: d8eeff509c87fe0264cbb510132a0c5ffbf8a61ac79f8bd56980663b876d6e5d
4
+ data.tar.gz: ed88bdd49a00bc99866e8782eadcf7c3b155f5bf0e0e24e250dd6b04e58cbce9
5
5
  SHA512:
6
- metadata.gz: 1372ae1a4809b4dc43b537f214cbe2e0caabbfc4bbaa0e1c0e12edb83dbfa927807199b33be2e98bd5b77a7d5fbfa0061a46beeba64b8c2382dd4bda6390e9df
7
- data.tar.gz: 95b9ac13c41f8b2335562858875beb65f49b1571f19abe363e5ac9cea0a98d6ea57eed512e319c79585a7be979b5966a46cc01b548082faba3e44b0f9f9f8b77
6
+ metadata.gz: 180971c8bcb4837224b24d7e3c16cddf9dd78e2242dc7c93c0596d241ca733af3cc1fc925b1edc78c56fa4fdeb48af2d12bad1747186276f3c135c161b1e08b6
7
+ data.tar.gz: c28b91d6b07c4bfe566af03b2f7b25ad67538154433b16773067f1675948b16692c895ce5f7c7b28ec051478dff15755275cbd25837042e9fcde0c135108c8ea
@@ -2,8 +2,7 @@ require 'net/https'
2
2
  require 'json'
3
3
 
4
4
  module Berbix
5
-
6
- SDK_VERSION = '0.0.6'
5
+ SDK_VERSION = '0.0.11'
7
6
  CLOCK_DRIFT = 300
8
7
 
9
8
  class HTTPClient
@@ -13,10 +12,23 @@ module Berbix
13
12
  end
14
13
 
15
14
  class NetHTTPClient < HTTPClient
15
+ attr_reader :read_timeout
16
+ attr_reader :open_timeout
17
+
18
+ def initialize(opts={})
19
+ # Sets the defaults to align with the Net::HTTP defaults
20
+ @open_timeout = opts[:open_timeout] || 60
21
+ @read_timeout = opts[:read_timeout] || 60
22
+ end
23
+
16
24
  def request(method, url, headers, opts={})
17
25
  uri = URI(url)
18
26
  klass = if method == :post
19
27
  Net::HTTP::Post
28
+ elsif method == :patch
29
+ Net::HTTP::Patch
30
+ elsif method == :delete
31
+ Net::HTTP::Delete
20
32
  else
21
33
  Net::HTTP::Get
22
34
  end
@@ -29,26 +41,32 @@ module Berbix
29
41
  end
30
42
  cli = Net::HTTP.new(uri.host, uri.port).tap do |http|
31
43
  http.use_ssl = true
44
+ http.read_timeout = read_timeout
45
+ http.open_timeout = open_timeout
32
46
  end
33
47
  res = cli.request(req)
34
48
  code = res.code.to_i
35
49
  if code < 200 || code >= 300
36
- raise 'unexpected status code returned'
50
+ raise(Berbix::BerbixError, 'unexpected status code returned')
51
+ end
52
+ if code == 204
53
+ return
37
54
  end
38
55
  JSON.parse(res.body)
39
56
  end
40
57
  end
41
58
 
42
59
  class Tokens
43
- attr_reader :access_token, :client_token, :refresh_token, :expiry, :transaction_id, :user_id
60
+ attr_reader :access_token, :client_token, :refresh_token, :expiry, :transaction_id, :user_id, :response
44
61
 
45
- def initialize(refresh_token, access_token=nil, client_token=nil, expiry=nil, transaction_id=nil)
62
+ def initialize(refresh_token, access_token=nil, client_token=nil, expiry=nil, transaction_id=nil, response=nil)
46
63
  @refresh_token = refresh_token
47
64
  @access_token = access_token
48
65
  @client_token = client_token
49
66
  @expiry = expiry
50
67
  @transaction_id = transaction_id
51
68
  @user_id = transaction_id
69
+ @response = response
52
70
  end
53
71
 
54
72
  def refresh!(access_token, client_token, expiry, transaction_id)
@@ -85,6 +103,7 @@ module Berbix
85
103
  payload[:phone] = opts[:phone] unless opts[:phone].nil?
86
104
  payload[:customer_uid] = opts[:customer_uid].to_s unless opts[:customer_uid].nil?
87
105
  payload[:template_key] = opts[:template_key] unless opts[:template_key].nil?
106
+ payload[:hosted_options] = opts[:hosted_options] unless opts[:hosted_options].nil?
88
107
  fetch_tokens('/v0/transactions', payload)
89
108
  end
90
109
 
@@ -111,6 +130,25 @@ module Berbix
111
130
  token_auth_request(:get, tokens, '/v0/transactions')
112
131
  end
113
132
 
133
+ def delete_transaction(tokens)
134
+ token_auth_request(:delete, tokens, '/v0/transactions')
135
+ end
136
+
137
+ def update_transaction(tokens, opts={})
138
+ payload = {}
139
+ payload[:action] = opts[:action] unless opts[:action].nil?
140
+ payload[:note] = opts[:note] unless opts[:note].nil?
141
+ token_auth_request(:patch, tokens, '/v0/transactions', data: payload)
142
+ end
143
+
144
+ def override_transaction(tokens, opts={})
145
+ payload = {}
146
+ payload[:response_payload] = opts[:response_payload] unless opts[:response_payload].nil?
147
+ payload[:flags] = opts[:flags] unless opts[:flags].nil?
148
+ payload[:override_fields] = opts[:override_fields] unless opts[:override_fields].nil?
149
+ token_auth_request(:patch, tokens, '/v0/transactions/override', data: payload)
150
+ end
151
+
114
152
  # This method is deprecated, please use fetch_transaction instead
115
153
  def fetch_user(tokens)
116
154
  fetch_transaction(tokens)
@@ -148,14 +186,14 @@ module Berbix
148
186
  end
149
187
  end
150
188
 
151
- def token_auth_request(method, tokens, path)
189
+ def token_auth_request(method, tokens, path, opts={})
152
190
  refresh_if_necessary!(tokens)
153
191
  headers = {
154
192
  'Authorization' => 'Bearer ' + tokens.access_token,
155
193
  'Content-Type' => 'application/json',
156
194
  'User-Agent' => 'BerbixRuby/' + SDK_VERSION,
157
195
  }
158
- @http_client.request(method, @api_host + path, headers)
196
+ @http_client.request(method, @api_host + path, headers, opts)
159
197
  end
160
198
 
161
199
  def fetch_tokens(path, payload)
@@ -174,7 +212,8 @@ module Berbix
174
212
  result['access_token'],
175
213
  result['client_token'],
176
214
  Time.now + result['expires_in'],
177
- result['transaction_id'])
215
+ result['transaction_id'],
216
+ result)
178
217
  end
179
218
 
180
219
  def auth
@@ -200,4 +239,6 @@ module Berbix
200
239
  end
201
240
  end
202
241
 
242
+ class BerbixError < StandardError
243
+ end
203
244
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Levine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Backend SDKs to interact with the Berbix Verify API endpoints.
14
14
  email: eric@berbix.com