Class: Pcli::Services::ApiManager

Inherits:
Object
  • Object
show all
Defined in:
lib/pcli/services/api_manager.rb

Instance Method Summary collapse

Instance Method Details

#ensure_authenticated(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pcli/services/api_manager.rb', line 8

def ensure_authenticated(&block)
  unless api.token
    return ensure_authenticated(&block) if authenticate.run(true)
  end

  response = block.call

  return if response === false

  if response.failure? && response.known_error? && response.error.type == 'unauthenticated'
    output.puts
    output.puts(Pl.dim("You've been logged out. Please log in again."))
    output.puts
    return ensure_authenticated(&block) if authenticate.run(false)
  else
    response
  end
end