class CoinRail::HTTP::Authentication
Public Class Methods
new(app, key, secret)
click to toggle source
Calls superclass method
# File lib/coinrail/http.rb, line 27 def initialize(app, key, secret) super(app) @key = key @secret = secret end
Public Instance Methods
call(env)
click to toggle source
# File lib/coinrail/http.rb, line 33 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] || '' encoded_payload = Base64.strict_encode64(body) signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), @secret, encoded_payload) env[:request_headers]['X-COINRAIL-PAYLOAD'] = encoded_payload env[:request_headers]['X-COINRAIL-SIGNATURE'] = signature @app.call env end