From 38f5bc5baff1f97970e3430bfb90a61075e7a3fc Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Fri, 22 Oct 2010 22:56:01 +0000 Subject: [PATCH] Added ability to update the base URI in services, resources, and methods. git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@102 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef --- lib/google/api_client/discovery.rb | 40 ++++++++++++++++++++++++ spec/google/api_client/discovery_spec.rb | 12 +++++++ 2 files changed, 52 insertions(+) diff --git a/lib/google/api_client/discovery.rb b/lib/google/api_client/discovery.rb index 3de33bcef..9d8045e1e 100644 --- a/lib/google/api_client/discovery.rb +++ b/lib/google/api_client/discovery.rb @@ -89,6 +89,21 @@ module Google return @base ||= Addressable::URI.parse(self.description['baseUrl']) end + ## + # Updates the hierarchy of resources and methods with the new base. + # + # @param [Addressable::URI, #to_str, String] new_base + # The new base URI to use for the service. + def base=(new_base) + @base = Addressable::URI.parse(new_base) + self.resources.each do |resource| + resource.base = @base + end + self.methods.each do |method| + method.base = @base + end + end + ## # A list of resources available at the root level of this version of the # service. @@ -244,6 +259,21 @@ module Google # @return [Addressable::URI] The base URI that methods are joined to. attr_reader :base + ## + # Updates the hierarchy of resources and methods with the new base. + # + # @param [Addressable::URI, #to_str, String] new_base + # The new base URI to use for the resource. + def base=(new_base) + @base = Addressable::URI.parse(new_base) + self.resources.each do |resource| + resource.base = @base + end + self.methods.each do |method| + method.base = @base + end + end + ## # A list of sub-resources available on this resource. # @@ -340,6 +370,16 @@ module Google # The base URI that this method will be joined to. attr_reader :base + ## + # Updates the method with the new base. + # + # @param [Addressable::URI, #to_str, String] new_base + # The new base URI to use for the method. + def base=(new_base) + @base = Addressable::URI.parse(new_base) + @uri_template = nil + end + ## # Returns the RPC name for the method. # diff --git a/spec/google/api_client/discovery_spec.rb b/spec/google/api_client/discovery_spec.rb index 2d8d32f4f..25f53ce94 100644 --- a/spec/google/api_client/discovery_spec.rb +++ b/spec/google/api_client/discovery_spec.rb @@ -200,6 +200,18 @@ describe Google::APIClient, 'configured for the prediction API' do 'https://www.googleapis.com/prediction/v1/training?query=12345' end + it 'should allow modification to the base URIs for testing purposes' do + prediction = @client.discovered_service('prediction', 'v1') + prediction.base = 'https://testing-domain.googleapis.com/prediction/v1/' + request = @client.generate_request( + prediction.training.insert, + {'query' => '123'} + ) + method, uri, headers, body = request + uri.should == + 'https://testing-domain.googleapis.com/prediction/v1/training?query=123' + end + it 'should generate signed requests' do @client.authorization = :oauth_1 @client.authorization.token_credential_key = '12345'