Class: Btce::Bus
- Inherits:
-
Object
- Object
- Btce::Bus
- Defined in:
- lib/btce/bus.rb
Instance Method Summary collapse
-
#initialize(api_key, api_secret) ⇒ Bus
constructor
A new instance of Bus.
- #request(data) ⇒ Object
- #sign(data) ⇒ Object
Constructor Details
#initialize(api_key, api_secret) ⇒ Bus
Returns a new instance of Bus.
25 26 27 28 29 |
# File 'lib/btce/bus.rb', line 25 def initialize(api_key, api_secret) @api_key = api_key @api_secret = api_secret @nonce = 0 end |
Instance Method Details
#request(data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/btce/bus.rb', line 31 def request(data) # Timestamp for the request data[:nonce] = Time::now.to_i + @nonce @nonce += 1 # Form parametrized string postdata = data.collect do |key, value| "#{key}=#{CGI::escape(value.to_s)}" end.join('&') # Open HTTPS connection Net::HTTP.start(Btce::Api::HOST, Btce::Api::PORT, :use_ssl => true) do |http| # Headers setup headers = { 'Sign' => sign(postdata), 'Key' => @api_key, 'User-Agent' => Btce::Api::AGENT } # Send signed data return http.post(Btce::Api::API_URL, postdata, headers).body end end |