Class: EY::CLI::API

Inherits:
API show all
Defined in:
lib/engineyard/cli/api.rb

Constant Summary

Constants inherited from API

API::USER_AGENT_STRING

Instance Attribute Summary

Attributes inherited from API

#token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from API

#==, #apps, #apps_for_repo, #environments, read_token, request, #resolver, save_token

Constructor Details

#initialize(token = nil) ⇒ API

Returns a new instance of API.

Raises:



5
6
7
8
9
10
# File 'lib/engineyard/cli/api.rb', line 5

def initialize(token = nil)
  @token = token
  @token ||= self.class.read_token
  @token ||= self.class.fetch_token
  raise EY::Error, "Sorry, we couldn't get your API token." unless @token
end

Class Method Details

.fetch_tokenObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/engineyard/cli/api.rb', line 26

def self.fetch_token
  EY.ui.info("We need to fetch your API token; please log in.")
  begin
    email    = EY.ui.ask("Email: ")
    password = EY.ui.ask("Password: ", true)
    super(email, password)
  rescue EY::API::InvalidCredentials
    EY.ui.warn "Invalid username or password; please try again."
    retry
  end
end

Instance Method Details

#refreshObject



22
23
24
# File 'lib/engineyard/cli/api.rb', line 22

def refresh
  @token = self.class.fetch_token
end

#requestObject



12
13
14
15
16
17
18
19
20
# File 'lib/engineyard/cli/api.rb', line 12

def request(*)
  begin
    super
  rescue EY::API::InvalidCredentials
    EY.ui.warn "Credentials rejected; please authenticate again."
    refresh
    retry
  end
end