From d2907c9d7959f4e88daebfb6685e714d7e971526 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Wed, 21 Sep 2011 10:51:51 +0300 Subject: [PATCH] Added better support for user IP and developer key across all APIs. --- lib/google/api_client.rb | 18 +++++++++++++++++- lib/google/api_client/reference.rb | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index 511ebf5a5..2921425f8 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -70,6 +70,8 @@ module Google # The writer method understands a few Symbols and will generate useful # default authentication mechanisms. self.authorization = options["authorization"] || :oauth_2 + self.key = options["key"] + self.user_ip = options["user_ip"] # The HTTP adapter controls all of the HTTP traffic the client generates. # By default, Net::HTTP is used, but adding support for other clients # is trivial. @@ -142,6 +144,18 @@ module Google return @authorization end + ## + # The application's API key issued by the API console. + # + # @return [String] The API key.. + attr_accessor :key + + ## + # The IP address of the user this request is being performed on behalf of. + # + # @return [String] The user's IP address. + attr_accessor :user_ip + ## # Returns the HTTP adapter used by the client. # @@ -440,7 +454,9 @@ module Google # object into a Hash and merge with the default options. options={ :version => 'v1', - :authorization => self.authorization + :authorization => self.authorization, + :key => self.key, + :user_ip => self.user_ip }.merge(options) # The Reference object is going to need this to do method ID lookups. options[:client] = self diff --git a/lib/google/api_client/reference.rb b/lib/google/api_client/reference.rb index 5085e0b00..73eecf198 100644 --- a/lib/google/api_client/reference.rb +++ b/lib/google/api_client/reference.rb @@ -29,6 +29,10 @@ module Google self.api_method = options[:api_method] self.parameters = options[:parameters] || {} + # These parameters are handled differently because they're not + # parameters to the API method, but rather to the API system. + self.parameters['key'] ||= options[:key] if options[:key] + self.parameters['user_ip'] ||= options[:user_ip] if options[:user_ip] self.headers = options[:headers] || [] if options[:body] self.body = options[:body]