Class: Slipsquare::Middleware::AskForCredentials

Inherits:
Base
  • Object
show all
Defined in:
lib/slipsquare/middleware/ask_for_credentials.rb

Overview

Ask for user credentials from the command line, then write them out.

Constant Summary

Constants inherited from Base

Base::CLEAR, Base::GREEN, Base::RED, Base::YELLOW

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Slipsquare::Middleware::Base

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/slipsquare/middleware/ask_for_credentials.rb', line 8

def call(env)

  say "If you dont know your app and secret key, try `slipsquare get-keys`"

  app_key = ask "Enter your App key:"
  secret_key = ask "Enter your Secret key:"

  Dropbox::API::Config.app_key    = app_key
  Dropbox::API::Config.app_secret = secret_key

  consumer = Dropbox::API::OAuth.consumer(:authorize)
  request_token = consumer.get_request_token
  say "Go to this url and click 'Authorize' to get the token:"
  say request_token.authorize_url, :green
  query  = request_token.authorize_url.split('?').last
  params = CGI.parse(query)
  token  = params['oauth_token'].first
  yes? "Once you authorize the app on Dropbox, type yes... "
  access_token  = request_token.get_access_token(:oauth_verifier => token)

  # Write the config file.
  env['config'].create_config_file(app_key, secret_key, access_token.token, access_token.secret)
  env['config'].reload!

  say "Credentials saved to ~/.slipsquare"

  @app.call(env)
end