Skip to content

Commit

Permalink
more helpful error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mojodna committed May 26, 2009
1 parent 02262c5 commit d45af77
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions lib/oauth/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,54 @@ def execute(stdout, stdin, stderr, arguments = [])
case command
# TODO move command logic elsewhere
when "authorize"
consumer = OAuth::Consumer.new \
options[:oauth_consumer_key],
options[:oauth_consumer_secret],
:access_token_url => options[:access_token_url],
:authorize_url => options[:authorize_url],
:request_token_url => options[:request_token_url],
:scheme => options[:scheme]

# parameters for OAuth 1.0a
oauth_verifier = nil

# get a request token
request_token = consumer.get_request_token(:oauth_callback => options[:oauth_callback])

if request_token.callback_confirmed?
stdout.puts "Server appears to support OAuth 1.0a; enabling support."
options[:version] = "1.0a"
end
begin
consumer = OAuth::Consumer.new \
options[:oauth_consumer_key],
options[:oauth_consumer_secret],
:access_token_url => options[:access_token_url],
:authorize_url => options[:authorize_url],
:request_token_url => options[:request_token_url],
:scheme => options[:scheme]

# parameters for OAuth 1.0a
oauth_verifier = nil

# get a request token
request_token = consumer.get_request_token(:oauth_callback => options[:oauth_callback])

if request_token.callback_confirmed?
stdout.puts "Server appears to support OAuth 1.0a; enabling support."
options[:version] = "1.0a"
end

stdout.puts "Please visit this url to authorize:"
stdout.puts request_token.authorize_url
stdout.puts "Please visit this url to authorize:"
stdout.puts request_token.authorize_url

if options[:version] == "1.0a"
stdout.puts "Please enter the verification code provided by the SP (oauth_verifier):"
oauth_verifier = stdin.gets.chomp
else
stdout.puts "Press return to continue..."
stdin.gets
end
if options[:version] == "1.0a"
stdout.puts "Please enter the verification code provided by the SP (oauth_verifier):"
oauth_verifier = stdin.gets.chomp
else
stdout.puts "Press return to continue..."
stdin.gets
end

begin
# get an access token
access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
begin
# get an access token
access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)

stdout.puts "Response:"
access_token.params.each do |k,v|
stdout.puts " #{k}: #{v}" unless k.is_a?(Symbol)
stdout.puts "Response:"
access_token.params.each do |k,v|
stdout.puts " #{k}: #{v}" unless k.is_a?(Symbol)
end
rescue OAuth::Unauthorized => e
stderr.puts "A problem occurred while attempting to obtain an access token:"
stderr.puts e
stderr.puts e.request.body
end
rescue OAuth::Unauthorized => e
stderr.puts "A problem occurred while attempting to obtain an access token:"
stderr.puts "A problem occurred while attempting to authorize:"
stderr.puts e
stderr.puts e.request.body
end
when "query"
consumer = OAuth::Consumer.new \
Expand Down

0 comments on commit d45af77

Please sign in to comment.