Class: Bitbot::Trader::Providers::MtGox::HttpClient::HmacMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb

Overview

Signs request with hmac signature

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ 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 HmacMiddleware

Parameters:

  • app (Object)
  • options (Hash)


56
57
58
59
60
# File 'lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb', line 56

def initialize(app, options)
  super(app)
  @key    = options.fetch(:key)
  @secret = options.fetch(:secret)
end

Instance Attribute Details

#keyString (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.

API key

Returns:

  • (String)


37
38
39
# File 'lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb', line 37

def key
  @key
end

#secretString (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.

API secret

Returns:

  • (String)


45
46
47
# File 'lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb', line 45

def secret
  @secret
end

Class Method Details

.extract_params(env) ⇒ Array

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.

Extracts headers, path and body

Parameters:

  • env (#[])

    must respond to request_headers, url and body

Returns:

  • (Array)


23
24
25
26
27
28
29
# File 'lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb', line 23

def self.extract_params(env)
  headers = env[:request_headers]
  path = env[:url].to_s.split("/2/").last
  body = env[:body]

  [headers, path, body]
end

Instance Method Details

#call(env) ⇒ Object

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.

Adds signature to current request

Parameters:

  • env (Object)

Returns:

  • (Object)


70
71
72
73
74
# File 'lib/bitbot/trader/providers/mt_gox/http_client/hmac_middleware.rb', line 70

def call(env)
  headers, path, body = self.class.extract_params(env)
  prepare_headers(headers, path, body)
  @app.call(env)
end