Module: Bter::Request

Extended by:
Request
Included in:
Public, Request, Trade
Defined in:
lib/bter/request.rb

Constant Summary collapse

PUBLIC_URL =
'https://data.bter.com/api/1'
TRADE_URL =
'https://bter.com/api/1/private'

Instance Method Summary collapse

Instance Method Details

#public_request(method, pair = '') ⇒ Object



7
8
9
# File 'lib/bter/request.rb', line 7

def public_request(method, pair='')
  HTTParty.get("#{PUBLIC_URL}/#{method}/#{pair}").body
end

#signObject



32
33
34
35
36
# File 'lib/bter/request.rb', line 32

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) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bter/request.rb', line 11

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
  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
end