Class: Cobo::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/cobo/request.rb

Class Method Summary collapse

Class Method Details

.get(command, params = {}) ⇒ Object



4
5
6
7
8
9
# File 'lib/cobo/request.rb', line 4

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

.headers(command, method = 'GET', params = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/cobo/request.rb', line 22

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

.hostObject



18
19
20
# File 'lib/cobo/request.rb', line 18

def self.host
  Cobo.sandbox ? "https://api.sandbox.cobo.com" : "https://api.custody.cobo.com"
end

.post(command, params = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/cobo/request.rb', line 11

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