File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ class Consumer
4343 # Add a custom ca_file for consumer
4444 # :ca_file => '/etc/certs.pem'
4545
46+ # Possible values:
47+ #
48+ # nil, false - no debug output
49+ # true - uses $stdout
50+ # some_value - uses some_value
51+ :debug_output => nil ,
52+
4653 :oauth_version => "1.0"
4754 }
4855
@@ -87,6 +94,18 @@ def http_method
8794 @http_method ||= @options [ :http_method ] || :post
8895 end
8996
97+ def debug_output
98+ @debug_output ||= begin
99+ case @options [ :debug_output ]
100+ when nil , false
101+ when true
102+ $stdout
103+ else
104+ @options [ :debug_output ]
105+ end
106+ end
107+ end
108+
90109 # The HTTP object for the site. The HTTP Object is what you get when you do Net::HTTP.new
91110 def http
92111 @http ||= create_http
@@ -322,6 +341,8 @@ def create_http(_url = nil)
322341 http_object . read_timeout = http_object . open_timeout = @options [ :timeout ] || 30
323342 http_object . open_timeout = @options [ :open_timeout ] if @options [ :open_timeout ]
324343 http_object . ssl_version = @options [ :ssl_version ] if @options [ :ssl_version ]
344+ http_object . set_debug_output ( debug_output ) if debug_output
345+
325346 http_object
326347 end
327348
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ def test_initializer
3838 assert_equal "http://blabla.bla/oauth/example/authorize.php" , @consumer . authorize_url
3939 assert_equal :header , @consumer . scheme
4040 assert_equal :get , @consumer . http_method
41+ assert_nil @consumer . debug_output
4142 end
4243
4344 def test_defaults
@@ -58,6 +59,28 @@ def test_defaults
5859 assert_equal "http://twitter.com/oauth/authorize" , @consumer . authorize_url
5960 assert_equal :header , @consumer . scheme
6061 assert_equal :post , @consumer . http_method
62+ assert_nil @consumer . debug_output
63+ end
64+
65+ def test_debug_output_true
66+ @consumer = OAuth ::Consumer . new (
67+ "key" ,
68+ "secret" ,
69+ {
70+ :debug_output => true
71+ } )
72+ assert_equal $stdout, @consumer . debug_output
73+ end
74+
75+ def test_debug_output
76+ stringio = StringIO . new
77+ @consumer = OAuth ::Consumer . new (
78+ "key" ,
79+ "secret" ,
80+ {
81+ :debug_output => stringio
82+ } )
83+ assert_equal stringio , @consumer . debug_output
6184 end
6285
6386 def test_site_without_path
You can’t perform that action at this time.
0 commit comments