svb-client 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/client.rb +53 -45
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aca32fb2692dcf6e04accbe04d08fb12a24f7710
4
- data.tar.gz: 3c3656d50c033a04e4bf9bd810277b455650a602
3
+ metadata.gz: 0c673ca2d7ad819becedb6e323949101f805a7c2
4
+ data.tar.gz: 30baaa43661db9c8d98a18494c7952e5ad6f699e
5
5
  SHA512:
6
- metadata.gz: f0005c6f7c09ffc210068a1c3d60880c01d2b570fa79a04f0fed15fa5f67ffaa7e8c5d6eb755b890acbd469585ad9a36ce6d25185125f6895abbee13a9004120
7
- data.tar.gz: '0678d053956317c01ed63db50734c6e77c4144d21b549ac4b0d573804d2d28a7cf7837678b59e74020d8b87893a364279c1db229f123a0ecbc685a7cab0324ee'
6
+ metadata.gz: d74264f9786b791c53a4532ee6a5db5b24902cb49fa6ef18fcbb19f5d5847ed9857e9987103fdf957fcf153b107a4ec2d81b0b1795fc8bc2de160b2f97d74ebf
7
+ data.tar.gz: e0c2855747d1c51216e8912cac098dcc5204201ef4f21adb931b358e4b77e3a481e911641a5040f26d912c7f104afde5509f149c8262ae16a0f8c2201fb4e096
@@ -12,50 +12,58 @@ require 'Base64'
12
12
  require 'net/https'
13
13
  require 'uri'
14
14
 
15
- module SVB_API
16
- class Client
17
- def signature(timestamp, method, path, query, body)
18
- message = [timestamp, method, path, query, body].join("\n")
19
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), HMAC_SECRET, message)
20
- end
21
-
22
- def timestamp_header
23
- Time.now.to_i.to_s
24
- end
25
-
26
- def make_request(uri, request)
27
- http = Net::HTTP.new(uri.host, 443)
28
- http.use_ssl = true
29
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
30
-
31
- request["Authorization"] = "Bearer " + API_KEY
32
- request["Content-Type"] = "application/json"
33
- response = http.request(request)
34
- end
35
-
36
- def get(path, query)
37
- mytimestamp = timestamp_header
38
- signature = signature(mytimestamp, 'GET', path, query, '')
39
-
40
- uri = URI.parse(BASE_URL + path + query)
41
-
42
- request = Net::HTTP::Get.new(uri.request_uri)
43
- request["X-Timestamp"] = mytimestamp
44
- request["X-Signature"] = signature
45
- make_request(uri, request)
46
- end
47
-
48
- def post(path, jsonbody)
49
- mytimestamp = timestamp_header
50
- signature = signature(mytimestamp, 'POST', path, '', JSON.generate(jsonbody))
51
-
52
- uri = URI.parse(BASE_URL + path)
53
-
54
- request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
55
- request.body = jsonbody.to_json
56
- request["X-Timestamp"] = mytimestamp
57
- request["X-Signature"] = signature
58
- make_request(uri, request)
59
- end
15
+ class SVBClient
16
+ def initialize(api_key, hmac, enviro='', base_url='https://api.svb.com', company_id=nil, key_id=nil, partner_id=nil)
17
+ self.API_KEY = api_key
18
+ self.HMAC_SECRET = hmac
19
+ self.ENVIRO = enviro if ['live', 'test'].includes? enviro
20
+ self.BASE_URL = base_url
21
+ self.COMPANY_ID = company_id
22
+ self.KEY_ID = key_id
23
+ self.PARTNER_ID = partner_id
24
+ end
25
+
26
+ def signature(timestamp, method, path, query, body)
27
+ message = [timestamp, method, path, query, body].join("\n")
28
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), HMAC_SECRET, message)
29
+ end
30
+
31
+ def timestamp_header
32
+ Time.now.to_i.to_s
33
+ end
34
+
35
+ def make_request(uri, request)
36
+ http = Net::HTTP.new(uri.host, 443)
37
+ http.use_ssl = true
38
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
39
+
40
+ request["Authorization"] = "Bearer " + API_KEY
41
+ request["Content-Type"] = "application/json"
42
+ response = http.request(request)
43
+ end
44
+
45
+ def get(path, query)
46
+ mytimestamp = timestamp_header
47
+ signature = signature(mytimestamp, 'GET', path, query, '')
48
+
49
+ uri = URI.parse(BASE_URL + path + query)
50
+
51
+ request = Net::HTTP::Get.new(uri.request_uri)
52
+ request["X-Timestamp"] = mytimestamp
53
+ request["X-Signature"] = signature
54
+ make_request(uri, request)
55
+ end
56
+
57
+ def post(path, jsonbody)
58
+ mytimestamp = timestamp_header
59
+ signature = signature(mytimestamp, 'POST', path, '', JSON.generate(jsonbody))
60
+
61
+ uri = URI.parse(BASE_URL + path)
62
+
63
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
64
+ request.body = jsonbody.to_json
65
+ request["X-Timestamp"] = mytimestamp
66
+ request["X-Signature"] = signature
67
+ make_request(uri, request)
60
68
  end
61
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silicon Valley Bank