Skip to content

Commit

Permalink
Add support for using a Google API key.
Browse files Browse the repository at this point in the history
  • Loading branch information
nreckart committed Sep 18, 2012
1 parent 642ac16 commit cd45b3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/gattica/engine.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Engine
# +:profile_id+:: Use this Google Analytics profile_id (default is nil) # +:profile_id+:: Use this Google Analytics profile_id (default is nil)
# +:timeout+:: Set Net:HTTP timeout in seconds (default is 300) # +:timeout+:: Set Net:HTTP timeout in seconds (default is 300)
# +:token+:: Use an authentication token you received before # +: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) # +:verify_ssl+:: Verify SSL connection (default is true)
def initialize(options={}) def initialize(options={})
@options = Settings::DEFAULT_OPTIONS.merge(options) @options = Settings::DEFAULT_OPTIONS.merge(options)
Expand Down Expand Up @@ -153,12 +154,19 @@ def token=(token)


###################################################################### ######################################################################
private 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 # 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 # sure it's valid and not an error


def do_http_get(query_string) def do_http_get(query_string)
response = @http.get(query_string, @headers) response = @http.get(add_api_key(query_string), @headers)


# error checking # error checking
if response.code != '200' if response.code != '200'
Expand Down
1 change: 1 addition & 0 deletions lib/gattica/settings.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Settings
:email => nil, # eg: 'email@gmail.com' :email => nil, # eg: 'email@gmail.com'
:password => nil, # eg: '$up3r_$ekret' :password => nil, # eg: '$up3r_$ekret'
:token => nil, :token => nil,
:api_key => nil,
:profile_id => nil, :profile_id => nil,
:debug => false, :debug => false,
:headers => {}, :headers => {},
Expand Down

0 comments on commit cd45b3c

Please sign in to comment.