Class: Manabu::Connection::Auth
- Inherits:
 - 
      Object
      
        
- Object
 - Manabu::Connection::Auth
 
 
- Defined in:
 - lib/manabu/connection/auth.rb
 
Instance Attribute Summary collapse
- 
  
    
      #connection  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute connection.
 - 
  
    
      #host  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute host.
 - 
  
    
      #port  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute port.
 - 
  
    
      #refresh_token  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute refresh_token.
 - 
  
    
      #token  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute token.
 - 
  
    
      #transactor  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute transactor.
 - 
  
    
      #username  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute username.
 
Instance Method Summary collapse
- #_authenticate(username, password) ⇒ Object
 - #_refresh(tokens) ⇒ Object
 - #full_host ⇒ Object
 - 
  
    
      #initialize(username, password, host, port, **options)  ⇒ Auth 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Auth.
 - #stop ⇒ Object
 - #success? ⇒ Boolean
 
Constructor Details
#initialize(username, password, host, port, **options) ⇒ Auth
Returns a new instance of Auth.
      8 9 10 11 12 13 14 15 16 17 18 19 20  | 
    
      # File 'lib/manabu/connection/auth.rb', line 8 def initialize(username, password, host, port, **) @username = username @host = host @port = port @transactor = Transactor.new(host, port, .fetch(:force_secure_connection, true), .fetch(:transport_type, :msgpack), ) @connection = false _authenticate(username, password) ObjectSpace.define_finalizer(self, -> { @connection = false }) end  | 
  
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def connection @connection end  | 
  
#host ⇒ Object
Returns the value of attribute host.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def host @host end  | 
  
#port ⇒ Object
Returns the value of attribute port.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def port @port end  | 
  
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def refresh_token @refresh_token end  | 
  
#token ⇒ Object
Returns the value of attribute token.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def token @token end  | 
  
#transactor ⇒ Object
Returns the value of attribute transactor.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def transactor @transactor end  | 
  
#username ⇒ Object
Returns the value of attribute username.
      6 7 8  | 
    
      # File 'lib/manabu/connection/auth.rb', line 6 def username @username end  | 
  
Instance Method Details
#_authenticate(username, password) ⇒ Object
      34 35 36 37 38 39 40 41 42  | 
    
      # File 'lib/manabu/connection/auth.rb', line 34 def _authenticate(username, password) response = @transactor.post("authenticate", username: username, password: password) @connection = true @token = response[:tokens][:auth_token] @transactor. = @token _refresh(response[:tokens]) end  | 
  
#_refresh(tokens) ⇒ Object
      44 45 46 47 48 49 50 51 52 53 54 55 56 57  | 
    
      # File 'lib/manabu/connection/auth.rb', line 44 def _refresh(tokens) @refresh_token = tokens[:refresh_token] thread = Thread.new do loop do break unless @connection sleep(120) refresh_response = transactor.post("authenticate/refresh", refresh_token: @refresh_token ) @transactor. = refresh_response[:tokens][:auth_token] @refresh_token = refresh_response[:tokens][:refresh_token] end end end  | 
  
#full_host ⇒ Object
      30 31 32  | 
    
      # File 'lib/manabu/connection/auth.rb', line 30 def full_host @transactor.full_host end  | 
  
#stop ⇒ Object
      26 27 28  | 
    
      # File 'lib/manabu/connection/auth.rb', line 26 def stop() end  | 
  
#success? ⇒ Boolean
      22 23 24  | 
    
      # File 'lib/manabu/connection/auth.rb', line 22 def success?() @connection end  |