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
The HTTP header: “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.
9 10 11 12 13 |
# File 'lib/deribit/authentication.rb', line 9 def initialize(app, key, secret) super(app) @key = key @secret = secret end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/deribit/authentication.rb', line 15 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
Returns the HTTP header: “Authorization: deri-hmac-sha256 id=ClientId,ts=Timestamp,sig=Signature,nonce=Nonce”.
27 28 29 30 |
# File 'lib/deribit/authentication.rb', line 27 def header(env, , nonce) signature = Deribit.http_signature env, , nonce, @secret "deri-hmac-sha256 id=#{@key},ts=#{},sig=#{signature},nonce=#{nonce}" end |