Permalink
Browse files

Merging chrisle:master into our branch

  • Loading branch information...
2 parents f5bd930 + bb99363 commit 69849566311982e776732047c90e426b6ec0a897 @jasonfox jasonfox committed Mar 13, 2013
Showing with 41 additions and 23 deletions.
  1. +3 −15 Gemfile.lock
  2. +15 −4 README.md
  3. +1 −1 lib/gattica.rb
  4. +19 −2 lib/gattica/engine.rb
  5. +3 −1 lib/gattica/settings.rb
View
@@ -1,32 +1,20 @@
PATH
remote: .
specs:
-<<<<<<< HEAD
- gattica (0.5.1)
-=======
- gattica (0.6.0)
- gattica
->>>>>>> upstream/master
+ gattica (0.6.2)
hpricot
- test-unit
GEM
remote: http://rubygems.org/
specs:
hpricot (0.8.6)
-<<<<<<< HEAD
- rake (0.9.2.2)
-=======
->>>>>>> upstream/master
test-unit (2.4.5)
PLATFORMS
ruby
DEPENDENCIES
-<<<<<<< HEAD
- rake
-=======
+ bundler
gattica!
->>>>>>> upstream/master
+ hpricot
test-unit
View
@@ -119,8 +119,8 @@ Here are some additional examples that illustrate different things you can do wi
:start_date => '2011-01-01',
:end_date => '2011-04-01',
:dimensions => ['month', 'year'],
- :metrics => ['visits']
- :sort => ['-visits'],
+ :metrics => ['visits'],
+ :sort => ['-visits']
})
### Limiting results
@@ -130,7 +130,7 @@ Here are some additional examples that illustrate different things you can do wi
:start_date => '2011-01-01',
:end_date => '2011-04-01',
:dimensions => ['month', 'year'],
- :metrics => ['visits']
+ :metrics => ['visits'],
:max_results => 25
})
@@ -184,7 +184,7 @@ Here are some additional examples that illustrate different things you can do wi
# => "month,year,visitors\n\n01,2011, ...."
- # Long CSV will get you a few additional columns:
+ # Long CSV will get you a few additional columns:
long_csv = data.to_csv
# => "id,updated,title,month,year,visitors\n\nhttp:// ..."
@@ -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
@@ -25,7 +25,7 @@
# Please see the README for usage docs.
module Gattica
- VERSION = '0.6.2.1'
+ VERSION = '0.6.2'
# Creates a new instance of Gattica::Engine
def self.new(*args)
View
@@ -16,6 +16,7 @@ class Engine
# +:profile_id+:: Use this Google Analytics profile_id (default is nil)
# +:timeout+:: Set Net:HTTP timeout in seconds (default is 300)
# +:token+:: Use an authentication token you received before
+ # +:api_key+:: The Google API Key for your project
# +:verify_ssl+:: Verify SSL connection (default is true)
def initialize(options={})
@options = Settings::DEFAULT_OPTIONS.merge(options)
@@ -153,12 +154,19 @@ def token=(token)
######################################################################
private
+
+ # Add the Google API key to the query string, if one is specified in the options.
+
+ def add_api_key(query_string)
+ query_string += "&key=#{@options[:api_key]}" if @options[:api_key]
+ query_string
+ end
# Does the work of making HTTP calls and then going through a suite of tests on the response to make
# sure it's valid and not an error
def do_http_get(query_string)
- response = @http.get(query_string, @headers)
+ response = @http.get(add_api_key(query_string), @headers)
# error checking
if response.code != '200'
@@ -262,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]
@@ -22,11 +22,13 @@ module Settings
:email => nil, # eg: 'email@gmail.com'
:password => nil, # eg: '$up3r_$ekret'
:token => nil,
+ :api_key => nil,
:profile_id => nil,
:debug => false,
:headers => {},
:logger => Logger.new(STDOUT),
- :verify_ssl => true
+ :verify_ssl => true,
+ :http_proxy => {}
}
FILTER_METRIC_OPERATORS = %w{ == != > < >= <= }

0 comments on commit 6984956

Please sign in to comment.