svbclient 1.0.1
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 +7 -0
- data/lib/svbclient.rb +71 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42a556e0edf9db78bf377c8ada65f2997d3d3a31
|
4
|
+
data.tar.gz: 25954cbbb0467c600cbb359b15c288a401549440
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6e6a40815db05afbf2db6cd706b6ed3a2b8b9bf2d5354c7a7937c191496cbc8a7f17fd729b58e206f2ad6f23cd309a39032d3a2313a2936081d836df2cfed26
|
7
|
+
data.tar.gz: 777198b9c8e561f9407c9de07c5f471e943a28cc64c59dfcdc086acfee5830dc82c3213b43ffe8b8e17da48c71e4e87f2312656a6728ee4f09680cbfdca2544d
|
data/lib/svbclient.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# svb-client.rb
|
5
|
+
#
|
6
|
+
# Example of HMAC request signing for use with the SVB API.
|
7
|
+
# See for the full documentation http://docs.svbplatform.com/authentication/.
|
8
|
+
# Email apisupport@svb.com for help!
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'json'
|
12
|
+
require 'openssl'
|
13
|
+
require 'Base64'
|
14
|
+
require 'net/https'
|
15
|
+
require 'uri'
|
16
|
+
|
17
|
+
class SVBClient
|
18
|
+
def initialize(api_key, hmac, enviro='', base_url='https://api.svb.com', company_id=nil, key_id=nil, partner_id=nil)
|
19
|
+
@API_KEY = api_key
|
20
|
+
@HMAC_SECRET = hmac
|
21
|
+
@ENVIRO = enviro if ['live', 'test'].include? enviro
|
22
|
+
@BASE_URL = base_url
|
23
|
+
@COMPANY_ID = company_id
|
24
|
+
@KEY_ID = key_id
|
25
|
+
@PARTNER_ID = partner_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def signature(timestamp, method, path, query, body)
|
29
|
+
message = [timestamp, method, path, query, body].join("\n")
|
30
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @HMAC_SECRET, message)
|
31
|
+
end
|
32
|
+
|
33
|
+
def timestamp_header
|
34
|
+
Time.now.to_i.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def make_request(uri, request)
|
38
|
+
http = Net::HTTP.new(uri.host, 443)
|
39
|
+
http.use_ssl = true
|
40
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
41
|
+
|
42
|
+
request["Authorization"] = "Bearer " + @API_KEY
|
43
|
+
request["Content-Type"] = "application/json"
|
44
|
+
response = http.request(request)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get(path, query="")
|
48
|
+
mytimestamp = timestamp_header
|
49
|
+
signature = signature(mytimestamp, 'GET', path, query, '')
|
50
|
+
|
51
|
+
uri = URI.parse(@BASE_URL + path + query)
|
52
|
+
|
53
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
54
|
+
request["X-Timestamp"] = mytimestamp
|
55
|
+
request["X-Signature"] = signature
|
56
|
+
make_request(uri, request)
|
57
|
+
end
|
58
|
+
|
59
|
+
def post(path, jsonbody)
|
60
|
+
mytimestamp = timestamp_header
|
61
|
+
signature = signature(mytimestamp, 'POST', path, '', JSON.generate(jsonbody))
|
62
|
+
|
63
|
+
uri = URI.parse(@BASE_URL + path)
|
64
|
+
|
65
|
+
request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
|
66
|
+
request.body = jsonbody.to_json
|
67
|
+
request["X-Timestamp"] = mytimestamp
|
68
|
+
request["X-Signature"] = signature
|
69
|
+
make_request(uri, request)
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svbclient
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
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/svbclient.rb
|
20
|
+
homepage: http://rubygems.org/gems/svbclient
|
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: []
|