Sha256: 9f1cad388a888bf9f235cccd7d146f244e46b205a35341a93a22188eabc9f45f
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
module Cobo class Request def self.get(command, params = {} ) url = host + command headers = headers(command, 'GET', params) result = RestClient::Request.execute(method: :get, url: url, headers: headers.merge({params: params})) JSON.parse result end def self.post( command, params = {} ) url = host + command headers = headers(command, 'POST', params) result = RestClient::Request.execute(method: :post, url: url, payload: params, headers: headers) JSON.parse result end def self.host Cobo.sandbox ? "https://api.sandbox.cobo.com" : "https://api.custody.cobo.com" end def self.headers(command, method = 'GET', params = {}) nonce = (Time.zone.now.to_f * 1000).to_i.to_s params_str = params.stringify_keys.sort.map{|array| "#{array.first}=#{array.last}" }.join("&") content = [method, command, nonce, params_str].join("|") digest = OpenSSL::Digest.new('sha256') sign = OpenSSL::HMAC.hexdigest(digest, Cobo.secret, content) {"BIZ-API-KEY" => Cobo.key, "BIZ-API-SIGNATURE" => sign, "BIZ-API-NONCE" => nonce} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cobo-0.1.0 | lib/cobo/request.rb |