Use discovered 'rootUrl' as base URI for services

This commit is contained in:
remi Taylor 2015-04-06 21:38:42 -07:00
parent ae8a15ce76
commit 1ed677b796
2 changed files with 42 additions and 2 deletions

View File

@ -30,7 +30,7 @@ module Google
# Creates a description of a particular version of a service.
#
# @param [String] document_base
# Base URI for the service
# Base URI for the discovery document.
# @param [Hash] discovery_document
# The section of the discovery document that applies to this service
# version.
@ -126,6 +126,16 @@ module Google
return @discovery_document['features'] || []
end
##
# Returns the root URI for this service.
#
# @return [Addressable::URI] The root URI.
def root_uri
return @root_uri ||= (
Addressable::URI.parse(self.discovery_document['rootUrl'])
)
end
##
# Returns true if this API uses a data wrapper.
#
@ -148,7 +158,7 @@ module Google
def method_base
if @discovery_document['basePath']
return @method_base ||= (
self.document_base.join(Addressable::URI.parse(@discovery_document['basePath']))
self.root_uri.join(Addressable::URI.parse(@discovery_document['basePath']))
).normalize
else
return nil

View File

@ -473,6 +473,10 @@ RSpec.describe Google::APIClient do
).to_env(CLIENT.connection)
end).to raise_error(ArgumentError)
end
it 'should correctly determine the service root_uri' do
expect(@plus.root_uri.to_s).to eq('https://www.googleapis.com/')
end
end
describe 'with the adsense API' do
@ -659,4 +663,30 @@ RSpec.describe Google::APIClient do
expect(@drive.files.insert.media_upload.max_size).not_to eq(nil)
end
end
describe 'with the Pub/Sub API' do
before do
CLIENT.authorization = nil
@pubsub = CLIENT.discovered_api('pubsub', 'v1beta2')
end
it 'should generate requests against the correct URIs' do
conn = stub_connection do |stub|
stub.get('/v1beta2/projects/12345/topics') do |env|
expect(env[:url].host).to eq('pubsub.googleapis.com')
[200, {}, '{}']
end
end
request = CLIENT.execute(
:api_method => @pubsub.projects.topics.list,
:parameters => {'project' => 'projects/12345'},
:connection => conn
)
conn.verify
end
it 'should correctly determine the service root_uri' do
expect(@pubsub.root_uri.to_s).to eq('https://pubsub.googleapis.com/')
end
end
end