Class: Kucoin::Api::Middleware::AuthRequest

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/kucoin/api/middleware/auth_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, api_key, api_secret, api_passphrase) ⇒ AuthRequest

Returns a new instance of AuthRequest.



6
7
8
9
10
11
# File 'lib/kucoin/api/middleware/auth_request.rb', line 6

def initialize app, api_key, api_secret, api_passphrase
  super(app)
  @api_key = api_key.to_s
  @api_secret = api_secret.to_s
  @api_passphrase = api_passphrase.to_s
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/kucoin/api/middleware/auth_request.rb', line 13

def call env
  raise Kucoin::Api::MissingApiKeyError.new('API KEY not provided') if @api_key.empty?
  raise Kucoin::Api::MissingApiSecretError.new('API SECRET not provided') if @api_secret.empty?
  raise Kucoin::Api::MissingApiPassphraseError.new('API PASSPHRASE not provided') if @api_passphrase.empty?
  env[:request_headers]['KC-API-KEY'] = @api_key
  env[:request_headers]['KC-API-SIGN'] = signature(env)
  env[:request_headers]['KC-API-PASSPHRASE'] = @api_passphrase
  @app.call env
end