Class: Cryptoexchange::Services::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptoexchange/services/authentication.rb

Instance Method Summary collapse

Constructor Details

#initialize(action, exchange) ⇒ Authentication

Returns a new instance of Authentication.



3
4
5
6
# File 'lib/cryptoexchange/services/authentication.rb', line 3

def initialize(action, exchange)
  @action = action
  @exchange = exchange
end

Instance Method Details

#headers(payload) ⇒ Object

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/cryptoexchange/services/authentication.rb', line 12

def headers(payload)
  raise NotImplementedError, 'header method is not defined!'
end

#is_missing_credentials?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cryptoexchange/services/authentication.rb', line 20

def is_missing_credentials?
  missing_credentials.length > 0
end

#missing_credentialsObject



24
25
26
27
28
29
# File 'lib/cryptoexchange/services/authentication.rb', line 24

def missing_credentials
  credentials = Cryptoexchange::Credentials.get(@exchange).keys.map(&:to_sym)
  required_credentials.select do |required|
    !credentials.include?(required)
  end
end

#raise_credentials_missing_errorObject



31
32
33
# File 'lib/cryptoexchange/services/authentication.rb', line 31

def raise_credentials_missing_error
  raise Cryptoexchange::CredentialsMissingError, "#{missing_credentials.join(', ')} are required!"
end

#required_credentialsObject



35
36
37
38
39
40
41
# File 'lib/cryptoexchange/services/authentication.rb', line 35

def required_credentials
  # NOTE: For demonstration purposes
  case @action
  when :pairs, :market, :order_book, :trades
    []
  end
end

#signature(payload) ⇒ Object

Raises:

  • (NotImplementedError)


8
9
10
# File 'lib/cryptoexchange/services/authentication.rb', line 8

def signature(payload)
  raise NotImplementedError, 'signature method is not defined!'
end

#validate_credentials!Object



16
17
18
# File 'lib/cryptoexchange/services/authentication.rb', line 16

def validate_credentials!
  raise_credentials_missing_error if is_missing_credentials?
end