Added better support for user IP and developer key across all APIs.
authorBob Aman <bobaman@google.com>
Wed, 21 Sep 2011 07:51:51 +0000 (10:51 +0300)
committerBob Aman <bobaman@google.com>
Wed, 21 Sep 2011 07:51:51 +0000 (10:51 +0300)
lib/google/api_client.rb
lib/google/api_client/reference.rb

index 511ebf5a5c6929a487d56dd0437933b4905b40b2..2921425f80fbce218d5a25a7c24981e3785fe9fc 100644 (file)
@@ -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
index 5085e0b00cb741d9ea79d988bee45bc8eecdd193..73eecf19823eaba0d009759ffc592c613dd5335b 100644 (file)
@@ -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]