svbclient 1.0.1 → 1.0.2
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 +4 -4
- data/lib/svbclient.rb +40 -27
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f6557b74d73c62a95b4c39dfb6ee9c9d274c50
|
4
|
+
data.tar.gz: 0f455ab2544ac3e8fcec068f4fd00cc61757067a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f570ad57b85fe8cb01c7f40acdfaf015331fa86944024ade7d0b910208be4345acd0c5445b49db4bffe810311eef0d2d97750bf4e688c866b2845df484be8b1
|
7
|
+
data.tar.gz: 429b5d36664f5bba92b9de1982f6d2c0bfbb4da5f461803b34a16878d3b5d057db57878772ed5deca67cbee471641a746bb7608d886cde7a074e611b4b26cbce
|
data/lib/svbclient.rb
CHANGED
@@ -13,12 +13,17 @@ require 'openssl'
|
|
13
13
|
require 'Base64'
|
14
14
|
require 'net/https'
|
15
15
|
require 'uri'
|
16
|
+
require 'rest-client'
|
16
17
|
|
17
18
|
class SVBClient
|
18
19
|
def initialize(api_key, hmac, enviro='', base_url='https://api.svb.com', company_id=nil, key_id=nil, partner_id=nil)
|
19
20
|
@API_KEY = api_key
|
20
21
|
@HMAC_SECRET = hmac
|
21
|
-
|
22
|
+
if ['live', 'test'].include? enviro
|
23
|
+
@ENVIRO = enviro
|
24
|
+
else
|
25
|
+
@ENVIRO = nil
|
26
|
+
end
|
22
27
|
@BASE_URL = base_url
|
23
28
|
@COMPANY_ID = company_id
|
24
29
|
@KEY_ID = key_id
|
@@ -30,42 +35,50 @@ class SVBClient
|
|
30
35
|
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @HMAC_SECRET, message)
|
31
36
|
end
|
32
37
|
|
33
|
-
def
|
34
|
-
Time.now.to_i.to_s
|
35
|
-
|
38
|
+
def headers(method, path, query, body)
|
39
|
+
mytimestamp = Time.now.to_i.to_s
|
40
|
+
signature = signature(mytimestamp, method, path, query, body)
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
hs = {
|
43
|
+
"X-Timestamp": mytimestamp,
|
44
|
+
"X-Signature": signature,
|
45
|
+
"Authorization": "Bearer " + @API_KEY,
|
46
|
+
"Content-Type": "application/json"
|
47
|
+
}
|
48
|
+
hs["X-Environment"] = @ENVIRO unless @ENVIRO.nil?
|
49
|
+
hs["X-Company-Id"] = @COMPANY_ID unless @COMPANY_ID.nil?
|
50
|
+
hs["X-Key-Id"] = @KEY_ID unless @KEY_ID.nil?
|
51
|
+
hs["X-Partner-Id"] = @PARTNER_ID unless @PARTNER_ID.nil?
|
52
|
+
hs
|
53
|
+
end
|
41
54
|
|
42
|
-
|
43
|
-
|
44
|
-
|
55
|
+
def delete(path)
|
56
|
+
hs = headers('DELETE', path, '', '')
|
57
|
+
RestClient.delete(@BASE_URL + path, headers=hs)
|
45
58
|
end
|
46
59
|
|
47
60
|
def get(path, query="")
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
uri = URI.parse(@BASE_URL + path + query)
|
61
|
+
hs = headers('GET', path, query, '')
|
62
|
+
RestClient.get(@BASE_URL + path + '?' + query, headers=hs)
|
63
|
+
end
|
52
64
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
make_request(uri, request)
|
65
|
+
def patch(path, jsonbody)
|
66
|
+
hs = headers('PATCH', path, '', JSON.generate(jsonbody))
|
67
|
+
RestClient.patch(@BASE_URL + path, JSON.generate(jsonbody), headers=hs)
|
57
68
|
end
|
58
69
|
|
59
70
|
def post(path, jsonbody)
|
60
|
-
|
61
|
-
|
71
|
+
hs = headers('POST', path, '', JSON.generate(jsonbody))
|
72
|
+
RestClient.post(@BASE_URL + path, JSON.generate(jsonbody), headers=hs)
|
73
|
+
end
|
74
|
+
|
75
|
+
def upload(path, filesrc, mimetype)
|
76
|
+
mytimestamp = Time.now.to_i.to_s
|
77
|
+
signature = signature(mytimestamp, 'POST', path, '', '')
|
62
78
|
|
63
|
-
|
79
|
+
hs = headers('POST', path, '', '')
|
80
|
+
hs["Content-Type"] = "multipart/form-data"
|
64
81
|
|
65
|
-
|
66
|
-
request.body = jsonbody.to_json
|
67
|
-
request["X-Timestamp"] = mytimestamp
|
68
|
-
request["X-Signature"] = signature
|
69
|
-
make_request(uri, request)
|
82
|
+
RestClient.post(@BASE_URL + path, { :file => filesrc, :multipart => true, 'Content-Type': mimetype }, headers=hs)
|
70
83
|
end
|
71
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svbclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Silicon Valley Bank
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-06-02 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Silicon Valley Bank API helper library
|
14
28
|
email: apisupport@svb.com
|
15
29
|
executables: []
|