Class: SVBClient
- Inherits:
-
Object
- Object
- SVBClient
- Defined in:
- lib/svbclient.rb
Defined Under Namespace
Classes: ACH, ACHHandler, Onboarding
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, query = "") ⇒ Object
- #headers(method, path, query, body) ⇒ Object
-
#initialize(api_key, hmac, base_url: 'https://api.svb.com') ⇒ SVBClient
constructor
A new instance of SVBClient.
- #patch(path, jsonbody) ⇒ Object
- #post(path, jsonbody) ⇒ Object
- #signature(timestamp, method, path, query, body) ⇒ Object
- #upload(path, filesrc, mimetype) ⇒ Object
Constructor Details
#initialize(api_key, hmac, base_url: 'https://api.svb.com') ⇒ SVBClient
Returns a new instance of SVBClient.
19 20 21 22 23 |
# File 'lib/svbclient.rb', line 19 def initialize(api_key, hmac, base_url: 'https://api.svb.com') @API_KEY = api_key @HMAC_SECRET = hmac @BASE_URL = base_url end |
Instance Method Details
#delete(path) ⇒ Object
42 43 44 45 |
# File 'lib/svbclient.rb', line 42 def delete(path) hs = headers('DELETE', path, '', '') RestClient.delete(@BASE_URL + path, headers=hs) end |
#get(path, query = "") ⇒ Object
47 48 49 50 |
# File 'lib/svbclient.rb', line 47 def get(path, query="") hs = headers('GET', path, query, '') RestClient.get(@BASE_URL + path + '?' + query, headers=hs) end |
#headers(method, path, query, body) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/svbclient.rb', line 30 def headers(method, path, query, body) = Time.now.to_i.to_s signature = signature(, method, path, query, body) { "X-Timestamp": , "X-Signature": signature, "Authorization": "Bearer " + @API_KEY, "Content-Type": "application/json" } end |
#patch(path, jsonbody) ⇒ Object
52 53 54 55 56 |
# File 'lib/svbclient.rb', line 52 def patch(path, jsonbody) jsonbody = { data: jsonbody } unless jsonbody.key? 'data' hs = headers('PATCH', path, '', jsonbody.to_json) RestClient.patch(@BASE_URL + path, jsonbody.to_json, headers=hs) end |
#post(path, jsonbody) ⇒ Object
58 59 60 61 62 |
# File 'lib/svbclient.rb', line 58 def post(path, jsonbody) jsonbody = { data: jsonbody } unless jsonbody.key? 'data' hs = headers('POST', path, '', jsonbody.to_json) RestClient.post(@BASE_URL + path, jsonbody.to_json, headers=hs) end |
#signature(timestamp, method, path, query, body) ⇒ Object
25 26 27 28 |
# File 'lib/svbclient.rb', line 25 def signature(, method, path, query, body) = [, method, path, query, body].join("\n") OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @HMAC_SECRET, ) end |
#upload(path, filesrc, mimetype) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/svbclient.rb', line 64 def upload(path, filesrc, mimetype) = Time.now.to_i.to_s signature = signature(, 'POST', path, '', '') hs = headers('POST', path, '', '') hs["Content-Type"] = "multipart/form-data" RestClient.post(@BASE_URL + path, { :file => filesrc, :multipart => true, 'Content-Type': mimetype }, headers=hs) end |