class ItBitSDK::Base

Constants

BASE_URL

Public Instance Methods

next_nonce() click to toggle source
# File lib/it_bit_sdk/base.rb, line 14
def next_nonce
  timestamp
end
send_request(verb, path, options = {}) click to toggle source
# File lib/it_bit_sdk/base.rb, line 18
def send_request(verb, path, options = {})
  timestamp = (Time.now.to_f * 1000).round.to_s
  nonce     = next_nonce
  payload   = options.empty? || verb == :get ? nil : JSON.dump(options)
  query     = options.any? && verb == :get ? "?#{URI.encode_www_form(options)}" : ''
  url       = "#{BASE_URL}#{path}#{query.gsub("%E2%80%8B", "")}"

  signature = ::ItBitSDK::MessageSigner.new.sign_message(verb, url, payload, nonce, timestamp)
  headers = {
    authorization: "#{ItBitSDK.client_key}:#{signature}",
    x_auth_timestamp: timestamp,
    x_auth_nonce: nonce,
    content_type: 'application/json'
  }

  begin
    response = RestClient::Request.execute(
      :method => verb,
      :url => url,
      :payload => payload,
      :headers => headers,
      :ssl_version => 'SSLv23')
  rescue => e
    response = e.response.body
  end

  JSON.parse(response.to_str) if response.to_s
end
timestamp() click to toggle source
# File lib/it_bit_sdk/base.rb, line 10
def timestamp
  Time.now.to_i
end