Sha256: 5f62690136a1dd448bbc210eafc117edf027832d1642fba99301d5d95d61de9d
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
require 'base64' module MtGox module Request def get(path, options={}) request(:get, path, options) end def post(path, options={}) request(:post, path, options) end private def request(method, path, options) response = connection.send(method) do |request| case method when :get request.url(path, options) when :post request.path = path request.body = body_from_options(options) request.headers = headers(request.body) end end if response.body['result'] && response.body['result'] == 'success' response.body['return'] else response.body end end def headers(request) signature = Base64.strict_encode64( OpenSSL::HMAC.digest 'sha512', Base64.decode64(secret), request ) {'Rest-Key' => key, 'Rest-Sign' => signature} end def body_from_options(options) add_nonce(options).collect{|k, v| "#{k}=#{v}"} * '&' end def add_nonce(options) options.merge!({nonce: (Time.now.to_f * 1000000).to_i}) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mtgox-1.0.0 | lib/mtgox/request.rb |
mtgox-0.9.1 | lib/mtgox/request.rb |