Class: Locomotive::Wagon::AuthenticateCommand
- Inherits:
-
Struct
- Object
- Struct
- Locomotive::Wagon::AuthenticateCommand
- Includes:
- ApiConcern, NetrcConcern
- Defined in:
- lib/locomotive/wagon/commands/authenticate_command.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#password ⇒ Object
Returns the value of attribute password.
-
#platform_url ⇒ Object
Returns the value of attribute platform_url.
-
#shell ⇒ Object
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from NetrcConcern
#read_credentials_from_netrc, #write_credentials_to_netrc
Methods included from ApiConcern
#api_client, #api_credentials, #api_host, #api_site_client, #connection_information_from_env_and_path
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email
6 7 8 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 6 def email @email end |
#password ⇒ Object
Returns the value of attribute password
6 7 8 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 6 def password @password end |
#platform_url ⇒ Object
Returns the value of attribute platform_url
6 7 8 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 6 def platform_url @platform_url end |
#shell ⇒ Object
Returns the value of attribute shell
6 7 8 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 6 def shell @shell end |
Class Method Details
.authenticate(platform_url, email, password, shell) ⇒ Object
11 12 13 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 11 def self.authenticate(platform_url, email, password, shell) self.new(platform_url, email, password, shell).authenticate end |
Instance Method Details
#authenticate ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 15 def authenticate if api_key = fetch_api_key write_credentials_to_netrc(api_host, email, api_key) else shell.say "Sorry, we were unable to authenticate you on \"#{platform_url}\"", :red end !api_key.nil? end |
#create_account ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 41 def create_account name = shell.ask 'What is your name?' begin account = api_client.my_account.create(name: name, email: email, password: password) shell.say "Your account has been successfully created.", :green account.api_key rescue Locomotive::Coal::Error => e shell.say "We were unable to create your account, reason(s): #{e.}", :red false end end |
#fetch_api_key ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/locomotive/wagon/commands/authenticate_command.rb', line 25 def fetch_api_key if my_account shell.say "\nYou have been successfully authenticated.", :green my_account.api_key else shell.say "\nNo account found for #{email} or invalid credentials", :yellow # shall we create a new account? if shell.yes?('Do you want to create a new account? [Y/N]') create_account else false end end end |