Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #24 from whatthewhat/http-proxy

Add http proxy support
  • Loading branch information...
commit bb99363eabd1a4a69b5e139efce42d3a40fd8e88 2 parents b91a644 + 42d3c9c
@chrisle authored
Showing with 23 additions and 2 deletions.
  1. +11 −0 README.md
  2. +10 −1 lib/gattica/engine.rb
  3. +2 −1  lib/gattica/settings.rb
View
11 README.md
@@ -407,6 +407,17 @@ Google expects a special header in all HTTP requests called 'Authorization'. Ga
:headers => {'My-Special-Header':'my_custom_value'}
})
+Using http proxy
+-----------------
+
+You can set http proxy settings when you instantiate the Gattica object:
+
+ ga = Gattica.new({
+ :email => 'email@gmail.com',
+ :password => 'password',
+ :http_proxy => { :host => 'proxy.example.com', :port => 8080, :user => 'username', :password => 'password' }
+ })
+
<hr />
History
View
11 lib/gattica/engine.rb
@@ -270,13 +270,22 @@ def validate_and_clean(args)
def create_http_connection(server)
port = Settings::USE_SSL ? Settings::SSL_PORT : Settings::NON_SSL_PORT
- @http = Net::HTTP.new(server, port)
+ @http = @options[:http_proxy].any? ? http_proxy.new(server, port) : Net::HTTP.new(server, port)
@http.use_ssl = Settings::USE_SSL
@http.verify_mode = @options[:verify_ssl] ? Settings::VERIFY_SSL_MODE : Settings::NO_VERIFY_SSL_MODE
@http.set_debug_output $stdout if @options[:debug]
@http.read_timeout = @options[:timeout] if @options[:timeout]
end
+ def http_proxy
+ proxy_host = @options[:http_proxy][:host]
+ proxy_port = @options[:http_proxy][:port]
+ proxy_user = @options[:http_proxy][:user]
+ proxy_pass = @options[:http_proxy][:password]
+
+ Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass)
+ end
+
# Sets instance variables from options given during initialization and
def handle_init_options(options)
@logger = options[:logger]
View
3  lib/gattica/settings.rb
@@ -27,7 +27,8 @@ module Settings
:debug => false,
:headers => {},
:logger => Logger.new(STDOUT),
- :verify_ssl => true
+ :verify_ssl => true,
+ :http_proxy => {}
}
FILTER_METRIC_OPERATORS = %w{ == != > < >= <= }
Please sign in to comment.
Something went wrong with that request. Please try again.