class GatecoinAPI::Client::SigningMiddleware

Constants

API_PUBLIC_KEY
API_REQUEST_DATE
API_REQUEST_SIGNATURE

Public Class Methods

new(app, public_key, private_key) click to toggle source
# File lib/gatecoin-api/client.rb, line 229
def initialize(app, public_key, private_key)
  @app         = app
  @public_key  = public_key
  @private_key = private_key
end

Public Instance Methods

call(env) click to toggle source
# File lib/gatecoin-api/client.rb, line 235
def call(env)
  env[:request_headers][API_PUBLIC_KEY]        = @public_key
  env[:request_headers][API_REQUEST_DATE]      = Time.now.to_f.round(3).to_s
  env[:request_headers][API_REQUEST_SIGNATURE] = signature(env)
  @app.call(env)
end
signature(env) click to toggle source

Base64Encode(

HMAC-SHA256(
  (“POST" + "https://staging.gatecoin.com/api/RegisterUser” +
   "application/json" + "1447700841.477091").downcase,
  @private_key
)

)

# File lib/gatecoin-api/client.rb, line 249
def signature(env)
  http_method  = env[:method].to_s.upcase
  content_type = http_method == 'GET' ? '' : env[:request_headers][:content_type]
  message      = "#{http_method}#{env[:url]}#{content_type}#{env[:request_headers][API_REQUEST_DATE]}".downcase
  Base64.strict_encode64 OpenSSL::HMAC.digest('sha256', @private_key, message)
end