Class: Quandl::Command::Tasks::Login

Inherits:
Base
  • Object
show all
Defined in:
lib/quandl/command/tasks/login.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options, #request_timer

Instance Method Summary collapse

Methods inherited from Base

#ask_yes_or_no, authenticated_users_only!, autoload_client_library, call, #call, command_name, configure, #current_user, #debug, description, disable!, disable_in_gem!, disabled?, #error, #fatal, #force_yes?, #info, inherited, #initialize, lang, language, #logger, options, #summarize, #summarize_hash, syntax, t, #table, #verbose?, warn_unauthenticated_users

Constructor Details

This class inherits a constructor from Quandl::Command::Tasks::Base

Instance Method Details

#authenticate!Object



19
20
21
22
# File 'lib/quandl/command/tasks/login.rb', line 19

def authenticate!
  return  if options.method == 'password'
  
end

#executeObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/quandl/command/tasks/login.rb', line 8

def execute
  authenticate!
  reload_session!
  if current_user.present?
    info "You have successfully authenticated!"
    info current_user.info
  else
    error "Failed to authenticate!"
  end
end

#execute_password_loginObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/quandl/command/tasks/login.rb', line 30

def 
  # request login and password
   = ask("Username or Email: ")
  password = ask("Password:  "){ |q| q.echo = "*" }
  # attempt to login
  user = Quandl::Client::User.( login: , password: password )
  # fail on errors
  return error( user.human_status ) unless user.auth_token.present?
  # output qdf
  write_auth_token(user.auth_token)
  info "You've successfully authorized #{}!"
end

#execute_token_loginObject



24
25
26
27
28
# File 'lib/quandl/command/tasks/login.rb', line 24

def 
  info("Obtain your Auth Token from this page: http://www.quandl.com/users/info")
  token = ask("Auth Token:  "){ |q| q.echo = "*" }
  write_auth_token(token)
end

#write_auth_token(token) ⇒ Object



43
44
45
# File 'lib/quandl/command/tasks/login.rb', line 43

def write_auth_token(token)
  QConfig.configuration.token = token
end