berbix 0.0.3 → 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/berbix.rb +28 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9b53c729e6703efb663060b297a04b1a8a5bb3d672cd167474d9a0f9cc55183
4
- data.tar.gz: '079d33739bae65f6421554fa8db553de49189fd5e19076ef2d2491f3a479cdd4'
3
+ metadata.gz: a623bd8b3c467b7821497d7fae7b39423e5c0d7e115895c96af431903f16eb5a
4
+ data.tar.gz: 9ad98f9ce7c872cba73dcde207beef4ea4e010656981427c1d86c0e44968c8bd
5
5
  SHA512:
6
- metadata.gz: 5ccdaf863d45c20f9f47191358278d341802f794ce17f7e3cd73cb2b8254cc6b90310397aecc975e2ddae45ea5a458e0d8f9f532782914f864c3983a8c427911
7
- data.tar.gz: 32a4b31c0c03efb526a2d161f756d469f6b96e77ba8d6de61d6d54838cf167b483bbf4473694fe9f5048fa9b028424d6dfe515451c8fa3d6df6ffd34391a3609
6
+ metadata.gz: 8ab58b14a285077d3b1d0016061ec418c14701008b690a84aa0076d63308f07d4a2e4e5dfb44bb1af09098db4df33cec27670cbe004129d1e941cfde1eb8ff59
7
+ data.tar.gz: 260e5f5f407cc89d2f10c7b8955f810c983bea7e1bf990369d1e6cd1565f5b2310fb9716bd5c107b14c01e036a4fd0dfda05eef459f5a73107ffa648e46c34fd
@@ -3,6 +3,9 @@ require 'json'
3
3
 
4
4
  module Berbix
5
5
 
6
+ SDK_VERSION = '0.0.5'
7
+ CLOCK_DRIFT = 300
8
+
6
9
  class HTTPClient
7
10
  def request(method, url, headers, opts={})
8
11
  raise 'subclass must implement request'
@@ -84,7 +87,8 @@ module Berbix
84
87
  payload = {}
85
88
  payload[:email] = opts[:email] unless opts[:email].nil?
86
89
  payload[:phone] = opts[:phone] unless opts[:phone].nil?
87
- payload[:customer_uid] = opts[:customer_uid] unless opts[:customer_uid].nil?
90
+ payload[:customer_uid] = opts[:customer_uid].to_s unless opts[:customer_uid].nil?
91
+ payload[:template_key] = opts[:template_key] unless opts[:template_key].nil?
88
92
  fetch_tokens('/v0/transactions', payload)
89
93
  end
90
94
 
@@ -121,6 +125,24 @@ module Berbix
121
125
  result['value']
122
126
  end
123
127
 
128
+ def validate_signature(secret, body, header)
129
+ parts = header.split(',')
130
+ # Version (parts[0]) is currently unused
131
+ timestamp = parts[1]
132
+ signature = parts[2]
133
+ if timestamp.to_i < Time.now.to_i - CLOCK_DRIFT
134
+ return false
135
+ end
136
+ digest = OpenSSL::Digest::SHA256.new
137
+ hmac = OpenSSL::HMAC.new(secret, digest)
138
+ hmac << timestamp
139
+ hmac << ','
140
+ hmac << secret
141
+ hmac << ','
142
+ hmac << body
143
+ hmac.hexdigest == signature
144
+ end
145
+
124
146
  private
125
147
 
126
148
  def refresh_if_necessary!(tokens)
@@ -135,12 +157,16 @@ module Berbix
135
157
  headers = {
136
158
  'Authorization' => 'Bearer ' + tokens.access_token,
137
159
  'Content-Type' => 'application/json',
160
+ 'User-Agent' => 'BerbixRuby/' + SDK_VERSION,
138
161
  }
139
162
  @http_client.request(method, @api_host + path, headers)
140
163
  end
141
164
 
142
165
  def fetch_tokens(path, payload)
143
- headers = { 'Content-Type' => 'application/json' }
166
+ headers = {
167
+ 'Content-Type' => 'application/json',
168
+ 'User-Agent' => 'BerbixRuby/' + SDK_VERSION,
169
+ }
144
170
  result = @http_client.request(
145
171
  :post,
146
172
  @api_host + path,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Levine