# 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.
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.
#
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
).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
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