Permalink
Browse files

Merge pull request #18 from nreckart/features/api-key

Add support for using a Google API key.
  • Loading branch information...
2 parents 913adaf + cd45b3c commit 7f725554af5ff5963672f046e5ca0105217e730c Chris Le committed Oct 1, 2012
Showing with 10 additions and 1 deletion.
  1. +9 −1 lib/gattica/engine.rb
  2. +1 −0 lib/gattica/settings.rb
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'
View
@@ -22,6 +22,7 @@ module Settings
:email => nil, # eg: 'email@gmail.com'
:password => nil, # eg: '$up3r_$ekret'
:token => nil,
+ :api_key => nil,
:profile_id => nil,
:debug => false,
:headers => {},

0 comments on commit 7f72555

Please sign in to comment.