Class: Bitflyer::HTTP::Authentication
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Bitflyer::HTTP::Authentication
- Defined in:
- lib/bitflyer/http.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, key, secret) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, key, secret) ⇒ Authentication
Returns a new instance of Authentication.
26 27 28 29 30 |
# File 'lib/bitflyer/http.rb', line 26 def initialize(app, key, secret) super(app) @key = key @secret = secret end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bitflyer/http.rb', line 32 def call(env) = Time.now.to_i.to_s method = env[:method].to_s.upcase path = env[:url].path + (env[:url].query ? '?' + env[:url].query : '') body = env[:body] || '' signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, + method + path + body) env[:request_headers]['ACCESS-KEY'] = @key if @key env[:request_headers]['ACCESS-TIMESTAMP'] = env[:request_headers]['ACCESS-SIGN'] = signature @app.call env end |