Skip to content
Browse files

start of proxy options

  • Loading branch information...
1 parent 282ca77 commit b72fcc771097fcd314034440a8e84e68edaec2db @tpitale tpitale committed Jun 16, 2011
View
9 lib/garb.rb
@@ -47,6 +47,10 @@ module Garb
extend self
+ class << self
+ attr_accessor :proxy_address, :proxy_port, :proxy_user, :proxy_password
+ end
+
def to_google_analytics(thing)
return thing.to_google_analytics if thing.respond_to?(:to_google_analytics)
@@ -66,4 +70,9 @@ def parse_properties(entry)
def parse_link(entry, rel)
entry['link'].detect {|link| link["rel"] == rel}['href']
end
+
+ # new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil)
+
+ # opts => open_timeout, read_timeout, ssl_timeout
+ # probably just support open_timeout
end
View
2 lib/garb/authentication_request.rb
@@ -25,7 +25,7 @@ def uri
end
def send_request(ssl_mode)
- http = Net::HTTP.new(uri.host, uri.port)
+ http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port)
http.use_ssl = true
http.verify_mode = ssl_mode
View
2 lib/garb/data_request.rb
@@ -29,7 +29,7 @@ def send_request
end
def single_user_request
- http = Net::HTTP.new(uri.host, uri.port)
+ http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.get("#{uri.path}#{query_string}", {'Authorization' => "GoogleLogin auth=#{@session.auth_token}", 'GData-Version' => '2'})
View
37 test/unit/garb/authentication_request_test.rb
@@ -8,6 +8,10 @@ class AuthenticationRequestTest < MiniTest::Unit::TestCase
context "An instance of the AuthenticationRequest class" do
setup { @request = AuthenticationRequest.new('email', 'password') }
+ teardown do
+ Garb.proxy_address = nil
+ Garb.proxy_port = nil
+ end
should "have a collection of parameters that include the email and password" do
expected =
@@ -27,7 +31,7 @@ class AuthenticationRequestTest < MiniTest::Unit::TestCase
assert_equal URI.parse('https://www.google.com/accounts/ClientLogin'), @request.uri
end
- should "be able to send a request to the GAAPI service with proper ssl" do
+ should "be able to send a request to the GAAPI service with proper ssl" do
@request.expects(:build_request).returns('post')
response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
@@ -39,12 +43,12 @@ class AuthenticationRequestTest < MiniTest::Unit::TestCase
m.expects(:request).with('post').yields(response)
end
- Net::HTTP.expects(:new).with('www.google.com', 443).returns(http)
+ Net::HTTP.expects(:new).with('www.google.com', 443, nil, nil).returns(http)
@request.send_request(OpenSSL::SSL::VERIFY_PEER)
end
- should "be able to send a request to the GAAPI service with ignoring ssl" do
+ should "be able to send a request to the GAAPI service with ignoring ssl" do
@request.expects(:build_request).returns('post')
response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
@@ -55,7 +59,7 @@ class AuthenticationRequestTest < MiniTest::Unit::TestCase
m.expects(:request).with('post').yields(response)
end
- Net::HTTP.expects(:new).with('www.google.com', 443).returns(http)
+ Net::HTTP.expects(:new).with('www.google.com', 443, nil, nil).returns(http)
@request.send_request(OpenSSL::SSL::VERIFY_NONE)
end
@@ -106,16 +110,31 @@ class AuthenticationRequestTest < MiniTest::Unit::TestCase
s.stubs(:request).yields(response)
end
- Net::HTTP.stubs(:new).with('www.google.com', 443).returns(http)
+ Net::HTTP.stubs(:new).with('www.google.com', 443, nil, nil).returns(http)
assert_raises(Garb::AuthenticationRequest::AuthError) do
@request.send_request(OpenSSL::SSL::VERIFY_NONE)
end
end
-
+
+ should "make use of Garb proxy settings in Net::HTTP request" do
+ @request.expects(:build_request).returns('post')
+
+ response = stub {|s| s.stubs(:is_a?).returns(true) }
+
+ http = mock do |m|
+ m.stubs(:use_ssl=)
+ m.stubs(:verify_mode=)
+ m.stubs(:request).yields(response)
+ end
+
+ Garb.proxy_address = '127.0.0.1'
+ Garb.proxy_port = '1234'
+
+ Net::HTTP.expects(:new).with('www.google.com', 443, '127.0.0.1', '1234').returns(http)
+
+ @request.send_request(nil)
+ end
end
-
-
-
end
end
View
9 test/unit/garb/data_request_test.rb
@@ -9,6 +9,11 @@ class DataRequestTest < MiniTest::Unit::TestCase
@session.auth_token = 'abcdefg123456'
end
+ teardown do
+ Garb.proxy_address = nil
+ Garb.proxy_port = nil
+ end
+
should "be able to build the query string from parameters" do
parameters = {'ids' => '12345', 'metrics' => 'country'}
data_request = DataRequest.new(@session, "", parameters)
@@ -96,7 +101,9 @@ class DataRequestTest < MiniTest::Unit::TestCase
}).returns(response)
end
- Net::HTTP.expects(:new).with('example.com', 443).returns(http)
+ Garb.proxy_address = "127.0.0.1"
+ Garb.proxy_port = "1234"
+ Net::HTTP.expects(:new).with('example.com', 443, "127.0.0.1", "1234").returns(http)
data_request = DataRequest.new(@session, 'https://example.com/data', 'key' => 'value')
assert_equal response, data_request.single_user_request

0 comments on commit b72fcc7

Please sign in to comment.
Something went wrong with that request. Please try again.