Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for using a Google API key.

  • Loading branch information...
commit cd45b3caeeedbe7f14a2450d19a55ccde45a895a 1 parent 642ac16
@nreckart nreckart authored
Showing with 10 additions and 1 deletion.
  1. +9 −1 lib/gattica/engine.rb
  2. +1 −0  lib/gattica/settings.rb
View
10 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'
View
1  lib/gattica/settings.rb
@@ -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 => {},
Please sign in to comment.
Something went wrong with that request. Please try again.