Class: BitflyerApi::HTTP::Middleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/bitflyer_api/http/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, key, secret) ⇒ Middleware

Returns a new instance of Middleware.



9
10
11
12
13
# File 'lib/bitflyer_api/http/middleware.rb', line 9

def initialize(app, key, secret)
  super(app)
  @key = key
  @secret = secret
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/bitflyer_api/http/middleware.rb', line 7

def key
  @key
end

#secretObject

Returns the value of attribute secret.



7
8
9
# File 'lib/bitflyer_api/http/middleware.rb', line 7

def secret
  @secret
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/bitflyer_api/http/middleware.rb', line 15

def call(env)
  return @app.call(env) if key.nil? || secret.nil?

  env[:request_headers]["ACCESS-KEY"] = key if key
  env[:request_headers]["ACCESS-TIMESTAMP"] = timestamp
  env[:request_headers]["ACCESS-SIGN"] = signature(env, secret)
  @app.call env
end