Class: Deribit::Authentication
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Deribit::Authentication
- Defined in:
- lib/deribit/authentication.rb
Overview
Deribit authentication implemented as Faraday middleware
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#header(env, timestamp, nonce) ⇒ Object
Authorization: deri-hmac-sha256 id=ClientId,ts=Timestamp,sig=Signature,nonce=Nonce.
-
#initialize(app, key, secret) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, key, secret) ⇒ Authentication
Returns a new instance of Authentication.
8 9 10 11 12 |
# File 'lib/deribit/authentication.rb', line 8 def initialize(app, key, secret) super(app) @key = key @secret = secret end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/deribit/authentication.rb', line 14 def call(env) return @app.call(env) if env['url'].path.include? 'public' return @app.call(env) if @key.nil? || @secret.nil? = Time.now.utc.to_i * 1000 nonce = rand(999999) env.request_headers['Authorization'] = header env, , nonce @app.call env end |
#header(env, timestamp, nonce) ⇒ Object
Authorization: deri-hmac-sha256 id=ClientId,ts=Timestamp,sig=Signature,nonce=Nonce
26 27 28 29 |
# File 'lib/deribit/authentication.rb', line 26 def header(env, , nonce) signature = Deribit.http_signature env, , nonce, @secret "deri-hmac-sha256 id=#{@key},ts=#{},sig=#{signature},nonce=#{nonce}" end |