Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add http proxy support

  • Loading branch information...
commit 42d3c9c3dc4acc60164e897a1367e88669e51ecc 1 parent b91a644
authored
11  README.md
Source Rendered
@@ -407,6 +407,17 @@ Google expects a special header in all HTTP requests called 'Authorization'.  Ga
407 407
         :headers => {'My-Special-Header':'my_custom_value'}
408 408
     })
409 409
         
  410
+Using http proxy
  411
+-----------------
  412
+
  413
+You can set http proxy settings when you instantiate the Gattica object:
  414
+
  415
+    ga = Gattica.new({ 
  416
+        :email => 'email@gmail.com', 
  417
+        :password => 'password',
  418
+        :http_proxy => { :host => 'proxy.example.com', :port => 8080, :user => 'username', :password => 'password' }
  419
+    })
  420
+    
410 421
 <hr />
411 422
 
412 423
 History
11  lib/gattica/engine.rb
@@ -270,13 +270,22 @@ def validate_and_clean(args)
270 270
 
271 271
     def create_http_connection(server)
272 272
       port = Settings::USE_SSL ? Settings::SSL_PORT : Settings::NON_SSL_PORT
273  
-      @http = Net::HTTP.new(server, port)
  273
+      @http = @options[:http_proxy].any? ? http_proxy.new(server, port) : Net::HTTP.new(server, port)
274 274
       @http.use_ssl = Settings::USE_SSL
275 275
       @http.verify_mode = @options[:verify_ssl] ? Settings::VERIFY_SSL_MODE : Settings::NO_VERIFY_SSL_MODE
276 276
       @http.set_debug_output $stdout if @options[:debug]
277 277
       @http.read_timeout = @options[:timeout] if @options[:timeout]
278 278
     end
279 279
 
  280
+    def http_proxy
  281
+      proxy_host = @options[:http_proxy][:host]
  282
+      proxy_port = @options[:http_proxy][:port]
  283
+      proxy_user = @options[:http_proxy][:user]
  284
+      proxy_pass = @options[:http_proxy][:password]
  285
+
  286
+      Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass)
  287
+    end
  288
+
280 289
     # Sets instance variables from options given during initialization and
281 290
     def handle_init_options(options)
282 291
       @logger = options[:logger]
3  lib/gattica/settings.rb
@@ -27,7 +27,8 @@ module Settings
27 27
         :debug => false,
28 28
         :headers => {},
29 29
         :logger => Logger.new(STDOUT),
30  
-        :verify_ssl => true
  30
+        :verify_ssl => true,
  31
+        :http_proxy => {}
31 32
     }
32 33
 
33 34
     FILTER_METRIC_OPERATORS = %w{ == != > < >= <= }

0 notes on commit 42d3c9c

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