Sha256: 258877277b8e54f76a63fa611df4dc596bb624331e9984e01348b8b478449b92

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

class Quandl::Command::Tasks::Login < Quandl::Command::Tasks::Base
  autoload_client_library
    
  description "Login to quandl with username and email."
  
  options String => { method: 'Login method? ( password | token )' }
  
  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
  
  def authenticate!
    return execute_password_login if options.method == 'password'
    execute_token_login
  end
  
  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
  
  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
  
  def write_auth_token(token)
    QConfig.configuration.token = token
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
quandl-0.2.27 lib/quandl/command/tasks/login.rb
quandl-0.2.26 lib/quandl/command/tasks/login.rb
quandl-0.2.25 lib/quandl/command/tasks/login.rb
quandl-0.2.24 lib/quandl/command/tasks/login.rb