svbclient 1.0.1 → 1.0.2

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/svbclient.rb +40 -27
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a556e0edf9db78bf377c8ada65f2997d3d3a31
4
- data.tar.gz: 25954cbbb0467c600cbb359b15c288a401549440
3
+ metadata.gz: e6f6557b74d73c62a95b4c39dfb6ee9c9d274c50
4
+ data.tar.gz: 0f455ab2544ac3e8fcec068f4fd00cc61757067a
5
5
  SHA512:
6
- metadata.gz: c6e6a40815db05afbf2db6cd706b6ed3a2b8b9bf2d5354c7a7937c191496cbc8a7f17fd729b58e206f2ad6f23cd309a39032d3a2313a2936081d836df2cfed26
7
- data.tar.gz: 777198b9c8e561f9407c9de07c5f471e943a28cc64c59dfcdc086acfee5830dc82c3213b43ffe8b8e17da48c71e4e87f2312656a6728ee4f09680cbfdca2544d
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
- @ENVIRO = enviro if ['live', 'test'].include? enviro
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 timestamp_header
34
- Time.now.to_i.to_s
35
- end
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
- 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
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
- request["Authorization"] = "Bearer " + @API_KEY
43
- request["Content-Type"] = "application/json"
44
- response = http.request(request)
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
- mytimestamp = timestamp_header
49
- signature = signature(mytimestamp, 'GET', path, query, '')
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
- request = Net::HTTP::Get.new(uri.request_uri)
54
- request["X-Timestamp"] = mytimestamp
55
- request["X-Signature"] = signature
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
- mytimestamp = timestamp_header
61
- signature = signature(mytimestamp, 'POST', path, '', JSON.generate(jsonbody))
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
- uri = URI.parse(@BASE_URL + path)
79
+ hs = headers('POST', path, '', '')
80
+ hs["Content-Type"] = "multipart/form-data"
64
81
 
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)
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.1
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: []