class Manabu::Connection::Auth

Attributes

connection[RW]
host[RW]
port[RW]
refresh_token[RW]
token[RW]
transactor[RW]
username[RW]

Public Class Methods

new(username, password, host, port, **options) click to toggle source
# File lib/manabu/connection/auth.rb, line 8
def initialize(username, password, host, port, **options)
  @username = username
  @host = host
  @port = port
  @transactor = Transactor.new(host, port,
                               options.fetch(:force_secure_connection, true),
                               options.fetch(:transport_type, :msgpack),
                               options)
  @connection = false
  _authenticate(username, password)

  ObjectSpace.define_finalizer(self, -> { @connection = false })
end

Public Instance Methods

_authenticate(username, password) click to toggle source
# 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.authorization = @token

  _refresh(response[:tokens])
end
_refresh(tokens) click to toggle source
# 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.authorization = refresh_response[:tokens][:auth_token]
      @refresh_token = refresh_response[:tokens][:refresh_token]
    end
  end
end
full_host() click to toggle source
# File lib/manabu/connection/auth.rb, line 30
def full_host
  @transactor.full_host
end
stop() click to toggle source
# File lib/manabu/connection/auth.rb, line 26
def stop()

end
success?() click to toggle source
# File lib/manabu/connection/auth.rb, line 22
def success?()
  @connection
end