class Ant::API
Attributes
api_key[RW]
api_secret[RW]
nonce_v[RW]
username[RW]
Public Class Methods
new(username, api_key, api_secret)
click to toggle source
# File lib/ant.rb, line 15 def initialize(username, api_key, api_secret) self.username = username self.api_key = api_key self.api_secret = api_secret end
Public Instance Methods
account()
click to toggle source
# File lib/ant.rb, line 38 def account self.api_call('account.htm', {}, true) end
api_call(method, param = {}, priv = false, is_json = true)
click to toggle source
# File lib/ant.rb, line 21 def api_call(method, param = {}, priv = false, is_json = true) url = "https://www.antpool.com/api/#{ method }" if priv self.nonce param.merge!(:key => self.api_key, :signature => self.signature.to_s.upcase, :nonce => self.nonce_v) end answer = self.post(url, param) # unfortunately, the API does not always respond with JSON, so we must only # parse as JSON if is_json is true. if is_json JSON.parse(answer) else answer end end
hashrate()
click to toggle source
# File lib/ant.rb, line 42 def hashrate self.api_call('hashrate.htm', {}, true) end
nonce()
click to toggle source
# File lib/ant.rb, line 46 def nonce self.nonce_v = (Time.now.to_f * 1000000).to_i.to_s end
post(url, param)
click to toggle source
# File lib/ant.rb, line 55 def post(url, param) # 由于服务器采用不安全openssl # uri = URI.parse(url) # https = Net::HTTP.new(uri.host, uri.port) # https.use_ssl = false # params = Addressable::URI.new # params.query_values = param # https.post(uri.path, params.query).body RestClient.post(url, param) end
signature()
click to toggle source
# File lib/ant.rb, line 50 def signature str = self.username + self.api_key + self.nonce_v OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), self.api_secret ,str) end