Class: Bitbot::Trader::Providers::MtGox::HttpClient
- Inherits:
-
Object
- Object
- Bitbot::Trader::Providers::MtGox::HttpClient
- Defined in:
- lib/bitbot/trader/providers/mt_gox/http_client.rb,
lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb
Overview
MtGox specific http client
Defined Under Namespace
Classes: HmacMiddleware
Constant Summary collapse
- HOST =
"https://data.mtgox.com/api/2/"
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
private
Return connection.
-
#nonce_generator ⇒ Object
readonly
private
Return nonce generator.
Class Method Summary collapse
-
.build(options) ⇒ HttpClient
private
Builds a new HttpClient object.
-
.make_connection(key, secret) ⇒ Faraday::Connection
private
Creates a new faraday connection object.
Instance Method Summary collapse
-
#initialize(connection, nonce_generator = Utils::NonceGenerator) ⇒ undefined
constructor
private
Initializes HttpClient object.
-
#post(path, options = {}) ⇒ Hash
private
Sends post request to given path.
Constructor Details
#initialize(connection, nonce_generator = Utils::NonceGenerator) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes HttpClient object
73 74 75 76 |
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 73 def initialize(connection, nonce_generator = Utils::NonceGenerator) @connection = connection @nonce_generator = nonce_generator end |
Instance Attribute Details
#connection ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return connection
54 55 56 |
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 54 def connection @connection end |
#nonce_generator ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return nonce generator
61 62 63 |
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 61 def nonce_generator @nonce_generator end |
Class Method Details
.build(options) ⇒ HttpClient
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a new HttpClient object
23 24 25 26 27 28 29 |
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 23 def self.build() key = .fetch(:key) secret = .fetch(:secret) connection = make_connection(key, secret) new(connection) end |
.make_connection(key, secret) ⇒ Faraday::Connection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new faraday connection object
40 41 42 43 44 45 46 |
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 40 def self.make_connection(key, secret) Faraday.new(url: HOST) do |faraday| faraday.request :url_encoded faraday.request :hmac, key: key, secret: secret faraday.adapter :net_http end end |
Instance Method Details
#post(path, options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sends post request to given path
89 90 91 92 93 |
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 89 def post(path, = {}) = .merge(nonce: @nonce_generator.generate) result = @connection.post(path, ).body JSON.parse(result) end |