def authorize
request_token = consumer.get_request_token
url = generate_authorize_url(request_token)
if options['prompt']
say "In a moment, you will be directed to the Twitter app authorization page."
say "Perform the following steps to complete the authorization process:"
say " 1. Sign in to Twitter"
say " 2. Press \"Authorize app\""
say " 3. Copy or memorize the supplied PIN"
say " 4. Return to the terminal to enter the PIN"
say
ask "Press [Enter] to open the Twitter app authorization page."
say
end
require 'launchy'
Launchy.open(url, :dry_run => options['display-url'])
pin = ask "Paste in the supplied PIN:"
access_token = request_token.get_access_token(:oauth_verifier => pin.chomp)
oauth_response = access_token.get('/1/account/verify_credentials.json')
screen_name = oauth_response.body.match(/"screen_name"\s*:\s*"(.*?)"/).captures.first
@rcfile.path = options['profile'] if options['profile']
@rcfile[screen_name] = {
options['consumer-key'] => {
'username' => screen_name,
'consumer_key' => options['consumer-key'],
'consumer_secret' => options['consumer-secret'],
'token' => access_token.token,
'secret' => access_token.secret,
}
}
@rcfile.active_profile = {'username' => screen_name, 'consumer_key' => options['consumer-key']}
say "Authorization successful."
end