module HexTokenBot::ChannelApi::Bter::Request

Constants

PUBLIC_URL
TRADE_URL

Private Instance Methods

make_hash(json_object) click to toggle source
# File lib/hex_token_bot/channel_api/bter/request.rb, line 44
def make_hash(json_object)
  JSON.parse(json_object, {:symbolize_names => true})
end
public_request(method, pair='', tid=nil) click to toggle source
# File lib/hex_token_bot/channel_api/bter/request.rb, line 10
def public_request(method, pair='', tid=nil)
  pair = pair + "/#{tid}" if tid.nil? == false
  response = HTTParty.get("#{PUBLIC_URL}/#{method}/#{pair}").body
  make_hash(response)
end
sign() click to toggle source
# File lib/hex_token_bot/channel_api/bter/request.rb, line 38
def sign
  hmac = OpenSSL::HMAC.new(@secret,OpenSSL::Digest::SHA512.new)
  @params = @params.collect {|k,v| "#{k}=#{v}"}.join('&')
  hmac.update(@params).to_s
end
trade_request(method, params=nil) click to toggle source
# File lib/hex_token_bot/channel_api/bter/request.rb, line 16
def trade_request(method, params=nil)
  if params.nil?
    @params = {:method => method}
  else
    @params = {:method => method}
    params.each do |param|
      @params.merge!(param)
    end
  end
  response = HTTParty.post(
      "#{TRADE_URL}/#{method}",
      :body => @params,
      :headers => {
          'KEY' => @key,
          'Sign' => sign,
          "Content-type" => "application/x-www-form-urlencoded",
          "Accept" => "application/x-www-form-urlencoded"
      }
  ).body
  make_hash(response)
end