Class: Quandl::Command::Tasks::Login
- Inherits:
-
Quandl::Command::Task
- Object
- Quandl::Command::Task
- Quandl::Command::Tasks::Login
- Defined in:
- lib/quandl/command/tasks/login.rb
Constant Summary
Constants included from Quandl::Command::Task::Updatable
Quandl::Command::Task::Updatable::VERSION_URL
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #execute ⇒ Object
- #execute_password_login ⇒ Object
- #execute_token_login ⇒ Object
- #write_auth_token(token) ⇒ Object
Methods included from Quandl::Command::Task::Inputable
#args_or_stdin, #each_line_in_background, #file_or_stdin
Methods included from Quandl::Command::Task::Reportable
#ask_to_send_crash_reports, #call
Methods included from Quandl::Command::Task::Clientable
Methods included from Quandl::Command::Task::Updatable
#check_for_update, #check_for_update_once_daily
Methods included from Quandl::Command::Task::Threading
#await_thread_pool_lock!, #background_job, #exiting?, #mutex, #obtain_thread_pool_lock, #release_thread_pool_lock, #shutdown_thread_pool_on_sigint, #thread_pool, #thread_pool_locked?, #thread_pool_locks, #threads, #threads?
Methods included from Quandl::Command::Task::Presentation
Methods included from Quandl::Command::Task::Logging
#configure_logger, #debug, #error, #fatal, #info, #initialize_logger, #log_request_time, #logger, #start_request_timer, #stderr_logger, #summarize, #summarize_hash, #table
Methods included from Quandl::Command::Task::Commandable
Methods included from Quandl::Command::Task::Validations
Methods included from Quandl::Command::Task::Callbacks
Methods included from Quandl::Command::Task::Configurable
#ask_for_confirmation!, #config, #confirmed?, #declared_params, #force_yes?, #page, #trace?, #verbose?
Instance Method Details
#authenticate! ⇒ Object
19 20 21 22 |
# File 'lib/quandl/command/tasks/login.rb', line 19 def authenticate! return execute_password_login if .method == 'password' execute_token_login end |
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/quandl/command/tasks/login.rb', line 8 def execute authenticate! clear_session! if current_user.present? info "You have successfully authenticated!" info current_user.info else error "Failed to authenticate!" end end |
#execute_password_login ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/quandl/command/tasks/login.rb', line 30 def execute_password_login # request login and password login = ask("Username or Email: ") password = ask("Password: "){ |q| q.echo = "*" } # attempt to login user = Quandl::Client::User.login( login: 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 #{login}!" end |
#execute_token_login ⇒ Object
24 25 26 27 28 |
# File 'lib/quandl/command/tasks/login.rb', line 24 def execute_token_login 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) config.token = token end |