From ef065ce8d656f383b691c2cd62c76c0748321d68 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Thu, 22 Sep 2011 13:49:46 +0300 Subject: [PATCH] Added code to include userIp and key parameters. --- lib/google/api_client/reference.rb | 6 +++- spec/google/api_client/discovery_spec.rb | 43 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/google/api_client/reference.rb b/lib/google/api_client/reference.rb index 73eecf198..572d33ddb 100644 --- a/lib/google/api_client/reference.rb +++ b/lib/google/api_client/reference.rb @@ -32,7 +32,7 @@ module Google # 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.parameters['userIp'] ||= options[:user_ip] if options[:user_ip] self.headers = options[:headers] || [] if options[:body] self.body = options[:body] @@ -55,6 +55,10 @@ module Google unless self.api_method self.http_method = options[:http_method] || 'GET' self.uri = options[:uri] + unless self.parameters.empty? + self.uri.query_values = + (self.uri.query_values || {}).merge(self.parameters) + end end end diff --git a/spec/google/api_client/discovery_spec.rb b/spec/google/api_client/discovery_spec.rb index 01e8205ed..7714e25c6 100644 --- a/spec/google/api_client/discovery_spec.rb +++ b/spec/google/api_client/discovery_spec.rb @@ -77,6 +77,49 @@ describe Google::APIClient do 'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest' end + it 'should correctly determine the discovery URI if :user_ip is set' do + @client.user_ip = '127.0.0.1' + request = @client.generate_request( + :http_method => 'GET', + :uri => @client.discovery_uri('prediction', 'v1.2'), + :authenticated => false + ) + http_method, uri, headers, body = request + uri.should === ( + 'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' + + '?userIp=127.0.0.1' + ) + end + + it 'should correctly determine the discovery URI if :key is set' do + @client.key = 'qwerty' + request = @client.generate_request( + :http_method => 'GET', + :uri => @client.discovery_uri('prediction', 'v1.2'), + :authenticated => false + ) + http_method, uri, headers, body = request + uri.should === ( + 'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' + + '?key=qwerty' + ) + end + + it 'should correctly determine the discovery URI if both are set' do + @client.key = 'qwerty' + @client.user_ip = '127.0.0.1' + request = @client.generate_request( + :http_method => 'GET', + :uri => @client.discovery_uri('prediction', 'v1.2'), + :authenticated => false + ) + http_method, uri, headers, body = request + uri.should === ( + 'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' + + '?key=qwerty&userIp=127.0.0.1' + ) + end + it 'should correctly generate API objects' do @client.discovered_api('prediction', 'v1.2').name.should == 'prediction' @client.discovered_api('prediction', 'v1.2').version.should == 'v1.2'