class Cased::CLI::Identity

Public Class Methods

new() click to toggle source
# File lib/cased/cli/identity.rb, line 6
def initialize
  @timeout = 30
end

Public Instance Methods

identify() click to toggle source
# File lib/cased/cli/identity.rb, line 10
def identify
  response = Cased.clients.cli.post('cli/applications/users/identify')
  case response.status
  when 201 # Created
    url = response.body.fetch('url')
    Cased::CLI::Log.log 'To login, please visit:'
    puts url
    poll(response.body['api_url'])
  when 401 # Unauthorized
    false
  end
end
poll(poll_url) click to toggle source
# File lib/cased/cli/identity.rb, line 23
def poll(poll_url)
  count = 0
  user_id = nil
  ip_address = nil

  while user_id.nil?
    count += 1
    response = Cased.clients.cli.get(poll_url)
    if response.success?
      user_id = response.body.dig('user', 'id')
      ip_address = response.body.fetch('ip_address')
    else
      sleep 1
    end
  end

  [user_id, ip_address]
end