svb-client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/client.rb +61 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aca32fb2692dcf6e04accbe04d08fb12a24f7710
|
4
|
+
data.tar.gz: 3c3656d50c033a04e4bf9bd810277b455650a602
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0005c6f7c09ffc210068a1c3d60880c01d2b570fa79a04f0fed15fa5f67ffaa7e8c5d6eb755b890acbd469585ad9a36ce6d25185125f6895abbee13a9004120
|
7
|
+
data.tar.gz: '0678d053956317c01ed63db50734c6e77c4144d21b549ac4b0d573804d2d28a7cf7837678b59e74020d8b87893a364279c1db229f123a0ecbc685a7cab0324ee'
|
data/lib/client.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
##
|
2
|
+
# svb-client.rb
|
3
|
+
#
|
4
|
+
# Example of HMAC request signing for use with the SVB API.
|
5
|
+
# See for the full documentation http://docs.svbplatform.com/authentication/.
|
6
|
+
# Email apisupport@svb.com for help!
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'json'
|
10
|
+
require 'openssl'
|
11
|
+
require 'Base64'
|
12
|
+
require 'net/https'
|
13
|
+
require 'uri'
|
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
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svb-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Silicon Valley Bank
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Silicon Valley Bank API helper library
|
14
|
+
email: apisupport@svb.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/client.rb
|
20
|
+
homepage: http://rubygems.org/gems/svb-client
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.12
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Silicon Valley Bank API helper library
|
44
|
+
test_files: []
|