From e09cc4923c22882f0959fa93f60368d77b524d74 Mon Sep 17 00:00:00 2001 From: Gene Drabkin Date: Thu, 18 Apr 2013 13:45:20 -0700 Subject: [PATCH] added 'verbose' flag to turn on logging for all http requests --- Gemfile | 3 +-- Gemfile.lock | 2 +- lib/oauth/consumer.rb | 9 +++++++++ test/test_consumer.rb | 13 +++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index c5c59f73..775f2670 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ -source :rubygems - +source 'https://rubygems.org' group :development do gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock index dd920eac..ad510903 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: actionpack (2.3.14) activesupport (= 2.3.14) diff --git a/lib/oauth/consumer.rb b/lib/oauth/consumer.rb index d4dd012d..1b6f21ac 100644 --- a/lib/oauth/consumer.rb +++ b/lib/oauth/consumer.rb @@ -43,6 +43,9 @@ class Consumer # Add a custom ca_file for consumer # :ca_file => '/etc/certs.pem' + # turn on logging for all HTTP requests (defaults to false) + :verbose => false, + :oauth_version => "1.0" } @@ -283,6 +286,10 @@ def proxy @options[:proxy] end + def verbose? + @options[:verbose] + end + protected # Instantiates the http object @@ -321,6 +328,8 @@ def create_http(_url = nil) http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 30 http_object.open_timeout = @options[:open_timeout] if @options[:open_timeout] + http_object.set_debug_output($stdout) if @options[:verbose] + http_object end diff --git a/test/test_consumer.rb b/test/test_consumer.rb index 136aeea8..ddda59bf 100644 --- a/test/test_consumer.rb +++ b/test/test_consumer.rb @@ -39,6 +39,7 @@ def test_initializer assert_equal "http://blabla.bla/oauth/example/authorize.php",@consumer.authorize_url assert_equal :header,@consumer.scheme assert_equal :get,@consumer.http_method + assert_equal false,@consumer.verbose? end def test_defaults @@ -59,6 +60,7 @@ def test_defaults assert_equal "http://twitter.com/oauth/authorize",@consumer.authorize_url assert_equal :header,@consumer.scheme assert_equal :post,@consumer.http_method + assert_equal false,@consumer.verbose? end def test_site_without_path @@ -209,6 +211,16 @@ def test_that_setting_ignore_callback_will_exclude_oauth_callback_in_request_opt assert_nil request_options[:oauth_callback] end + def test_verbose + @consumer=OAuth::Consumer.new( + "key", + "secret", + { + :verbose=>true + }) + assert_equal true,@consumer.verbose? + end + private def create_stub_http_response expected_body=nil @@ -217,4 +229,5 @@ def create_stub_http_response expected_body=nil stub_http_response.stubs(:body).tap {|expectation| expectation.returns(expected_body) unless expected_body.nil? } return stub_http_response end + end