module Cryptoprocessing::Authentication

Authentication methods for {Cryptoprocessing::Client}

Для аутентификации используется токен

@see api.cryptoprocessing.io/#152a3087-a02e-de76-f156-2015c2ccefef

Public Instance Methods

login(options) { |resp| ... } click to toggle source

Login user

Логин пользователя

@see api.cryptoprocessing.io/#e88a61dc-bb8f-e9cf-0e56-2729f200be9d

# File lib/cryptoprocessing/authentication.rb, line 42
def login(options)
  out = nil
  post('/auth/login', options) do |resp|
    @access_token = resp.body['auth_token']
    out = Cryptoprocessing::User.new self, resp.data
    yield(resp) if block_given?
  end
  out
end
login_from_netrc() click to toggle source
# File lib/cryptoprocessing/authentication.rb, line 18
def login_from_netrc
  return unless netrc?

  require 'netrc'
  info = Netrc.read netrc_file
  netrc_host = URI.parse(api_endpoint).host
  creds = info[netrc_host]
  if creds.nil?
    # creds will be nil if there is no netrc for this end point
    puts "Error loading credentials from netrc file for #{api_endpoint}"
  else
    creds = creds.to_a
    self.login = creds.shift
    self.password = creds.shift
  end
rescue LoadError
  puts "Please install netrc gem for .netrc support"
end
register(options) { |resp| ... } click to toggle source

Register user

Регистрация пользователя

@see api.cryptoprocessing.io/#b0ec8c86-4c57-de45-5aea-e1cb6483e591

# File lib/cryptoprocessing/authentication.rb, line 57
def register(options)
  out = nil
  post('/auth/register', options) do |resp|
    @access_token = resp.body['auth_token']
    out = Cryptoprocessing::User.new self, resp.data
    yield(resp) if block_given?
  end
  out
end
token_authenticated?() click to toggle source

Indicates if the client was supplied a bearer token

@return [Boolean]

# File lib/cryptoprocessing/authentication.rb, line 14
def token_authenticated?
  !!@access_token
end