Module: Cryptoprocessing::Authentication
- Included in:
- Client
- Defined in:
- lib/cryptoprocessing/authentication.rb
Overview
Authentication methods for Client
Для аутентификации используется токен
Instance Method Summary collapse
-
#login(options) ⇒ Object
Login user.
- #login_from_netrc ⇒ Object
-
#register(options) ⇒ Object
Register user.
-
#token_authenticated? ⇒ Boolean
Indicates if the client was supplied a bearer token.
Instance Method Details
#login(options) ⇒ Object
Login user
Логин пользователя
42 43 44 45 46 47 48 49 50 |
# File 'lib/cryptoprocessing/authentication.rb', line 42 def login() out = nil post('/auth/login', ) 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 ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
Register user
Регистрация пользователя
57 58 59 60 61 62 63 64 65 |
# File 'lib/cryptoprocessing/authentication.rb', line 57 def register() out = nil post('/auth/register', ) 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? ⇒ Boolean
Indicates if the client was supplied a bearer token
14 15 16 |
# File 'lib/cryptoprocessing/authentication.rb', line 14 def token_authenticated? !!@access_token end |