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
This commit is contained in:
Bob Aman 2010-10-22 22:56:01 +00:00
parent f63bf8199f
commit 38f5bc5baf
2 changed files with 52 additions and 0 deletions

View File

@ -89,6 +89,21 @@ module Google
return @base ||= Addressable::URI.parse(self.description['baseUrl']) return @base ||= Addressable::URI.parse(self.description['baseUrl'])
end 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 # A list of resources available at the root level of this version of the
# service. # service.
@ -244,6 +259,21 @@ module Google
# @return [Addressable::URI] The base URI that methods are joined to. # @return [Addressable::URI] The base URI that methods are joined to.
attr_reader :base 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. # 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. # The base URI that this method will be joined to.
attr_reader :base 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. # Returns the RPC name for the method.
# #

View File

@ -200,6 +200,18 @@ describe Google::APIClient, 'configured for the prediction API' do
'https://www.googleapis.com/prediction/v1/training?query=12345' 'https://www.googleapis.com/prediction/v1/training?query=12345'
end 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 it 'should generate signed requests' do
@client.authorization = :oauth_1 @client.authorization = :oauth_1
@client.authorization.token_credential_key = '12345' @client.authorization.token_credential_key = '12345'