Class: Cased::CLI::Identity
- Inherits:
-
Object
- Object
- Cased::CLI::Identity
- Defined in:
- lib/cased/cli/identity.rb
Instance Method Summary collapse
- #identify ⇒ Object
-
#initialize ⇒ Identity
constructor
A new instance of Identity.
- #poll(poll_url) ⇒ Object
Constructor Details
#initialize ⇒ Identity
Returns a new instance of Identity.
6 7 8 |
# File 'lib/cased/cli/identity.rb', line 6 def initialize @timeout = 30 end |
Instance Method Details
#identify ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |