Class: EPC::Command::LoginCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/login_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(email = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/epc/command/login_command.rb', line 6

def execute(email = nil)
  if blank?(email)
    say("You must supply an email address")
    return 1
  end
  
  password = options[:password]
  password = ask("Password: ") { |q| q.echo = '*' } unless password
  
  begin
    status, response, headers = client.post("#{EPC::Config::TOKENS_PATH}/retrieve", { :email => email, :password => password }, true)
    if status.successful? && response
      EPC::Config.store_caller_id(response[:caller_id])
      EPC::Config.store_auth_token(response[:authentication_token])
      EPC::Config.store_username(email)
      say("Successfully logged into [#{target_url}]")
    elsif response
      say("Login failed [#{response[:message]}]. Please make sure you entered the correct email and password.")
    end
    return status
  rescue Exception => ex
    say("Login failed [#{ex}].")
    return 1
  end    
end