Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: readmedia/gattica
base: f5bd9304b5
...
head fork: readmedia/gattica
compare: 6984956631
  • 9 commits
  • 5 files changed
  • 0 commit comments
  • 6 contributors
Commits on Sep 18, 2012
@nreckart nreckart Add support for using a Google API key. cd45b3c
@MartijnSch MartijnSch Adjust some typos d396f25
Commits on Sep 20, 2012
Chris Le Merge pull request #19 from MartijnSch/master
Fix some typos in the README
913adaf
Commits on Oct 01, 2012
Chris Le Merge pull request #18 from nreckart/features/api-key
Add support for using a Google API key.
7f72555
Commits on Jan 09, 2013
@ngpestelos ngpestelos bumps Gattica::VERSION to 0.6.2 8c5d8f6
Commits on Jan 19, 2013
@chrisle chrisle Merge pull request #23 from ngpestelos/master
bumps Gattica::VERSION to 0.6.2
b91a644
Commits on Feb 08, 2013
Mikhail Topolskiy Add http proxy support 42d3c9c
Commits on Feb 20, 2013
@chrisle chrisle Merge pull request #24 from whatthewhat/http-proxy
Add http proxy support
bb99363
Commits on Mar 13, 2013
@jasonfox jasonfox Merging chrisle:master into our branch 6984956
View
18 Gemfile.lock
@@ -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
19 README.md
@@ -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
2  lib/gattica.rb
@@ -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
21 lib/gattica/engine.rb
@@ -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]
View
4 lib/gattica/settings.rb
@@ -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{ == != > < >= <= }

No commit comments for this range

Something went wrong with that request. Please try again.