Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
source :rubygems

source 'https://rubygems.org'

group :development do
gem 'rake'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
actionpack (2.3.14)
activesupport (= 2.3.14)
Expand Down
9 changes: 9 additions & 0 deletions lib/oauth/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -283,6 +286,10 @@ def proxy
@options[:proxy]
end

def verbose?
@options[:verbose]
end

protected

# Instantiates the http object
Expand Down Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:

case @options[:verbose]
when false, nil
  nil
when true
  http_object.set_debug_output($stdout)
else
  http_object.set_debug_output(@options[:verbose])
end


http_object
end

Expand Down
13 changes: 13 additions & 0 deletions test/test_consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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