class Bitflyer::HTTP::Authentication
Public Class Methods
new(app, key, secret)
click to toggle source
Calls superclass method
# File lib/bitflyer/http.rb, line 28 def initialize(app, key, secret) super(app) @key = key @secret = secret end
Public Instance Methods
call(env)
click to toggle source
# File lib/bitflyer/http.rb, line 34 def call(env) return @app.call(env) if @key.nil? || @secret.nil? timestamp = 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, timestamp + method + path + body) env[:request_headers]['ACCESS-KEY'] = @key if @key env[:request_headers]['ACCESS-TIMESTAMP'] = timestamp env[:request_headers]['ACCESS-SIGN'] = signature @app.call env end