class ZaifWrapper::Client::ZaifParentApi

Constants

FUTURE_METHODS
FUTURE_REQUEST_URL_BASE
LEVERAGE_METHODS
LEVERAGE_REQUEST_URL_BASE
PRIVATE_METHODS
PRIVATE_REQUEST_URL_BASE
PUBLIC_METHODS
PUBLIC_REQUEST_URL_BASE

Public Instance Methods

create_signature(body) click to toggle source
# File lib/zaif_wrapper/client.rb, line 51
def create_signature(body)
  OpenSSL::HMAC::hexdigest(OpenSSL::Digest.new('sha512'), @api_secret, body.to_s)
end
get_nonce() click to toggle source
# File lib/zaif_wrapper/client.rb, line 47
def get_nonce
  Time.now.to_f.to_i
end
get_request(host, path) click to toggle source
# File lib/zaif_wrapper/client.rb, line 26
def get_request(host, path)
  response = RestClient.get "#{host}#{path}"
  JSON.parse(response.body)
end
post_request(body, host) click to toggle source
# File lib/zaif_wrapper/client.rb, line 31
def post_request(body, host)
  body.store('nonce', get_nonce)
  signature_text = ""
  body.each_with_index { |param, i|
    signature_text = signature_text + '&' if i != 0
    signature_text = "#{signature_text}#{param[0]}=#{param[1]}"
  }
  response = RestClient.post host, body, {
      content_type: :json,
      accept: :json,
      key: @api_key,
      sign: create_signature(signature_text)
  }
  JSON.parse(response.body)
end