File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
lib/google/api_client/discovery Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class API
30
30
# Creates a description of a particular version of a service.
31
31
#
32
32
# @param [String] document_base
33
- # Base URI for the service
33
+ # Base URI for the discovery document.
34
34
# @param [Hash] discovery_document
35
35
# The section of the discovery document that applies to this service
36
36
# version.
@@ -126,6 +126,16 @@ def features
126
126
return @discovery_document [ 'features' ] || [ ]
127
127
end
128
128
129
+ ##
130
+ # Returns the root URI for this service.
131
+ #
132
+ # @return [Addressable::URI] The root URI.
133
+ def root_uri
134
+ return @root_uri ||= (
135
+ Addressable ::URI . parse ( self . discovery_document [ 'rootUrl' ] )
136
+ )
137
+ end
138
+
129
139
##
130
140
# Returns true if this API uses a data wrapper.
131
141
#
@@ -148,7 +158,7 @@ def data_wrapper?
148
158
def method_base
149
159
if @discovery_document [ 'basePath' ]
150
160
return @method_base ||= (
151
- self . document_base . join ( Addressable ::URI . parse ( @discovery_document [ 'basePath' ] ) )
161
+ self . root_uri . join ( Addressable ::URI . parse ( @discovery_document [ 'basePath' ] ) )
152
162
) . normalize
153
163
else
154
164
return nil
Original file line number Diff line number Diff line change 473
473
) . to_env ( CLIENT . connection )
474
474
end ) . to raise_error ( ArgumentError )
475
475
end
476
+
477
+ it 'should correctly determine the service root_uri' do
478
+ expect ( @plus . root_uri . to_s ) . to eq ( 'https://www.googleapis.com/' )
479
+ end
476
480
end
477
481
478
482
describe 'with the adsense API' do
659
663
expect ( @drive . files . insert . media_upload . max_size ) . not_to eq ( nil )
660
664
end
661
665
end
666
+
667
+ describe 'with the Pub/Sub API' do
668
+ before do
669
+ CLIENT . authorization = nil
670
+ @pubsub = CLIENT . discovered_api ( 'pubsub' , 'v1beta2' )
671
+ end
672
+
673
+ it 'should generate requests against the correct URIs' do
674
+ conn = stub_connection do |stub |
675
+ stub . get ( '/v1beta2/projects/12345/topics' ) do |env |
676
+ expect ( env [ :url ] . host ) . to eq ( 'pubsub.googleapis.com' )
677
+ [ 200 , { } , '{}' ]
678
+ end
679
+ end
680
+ request = CLIENT . execute (
681
+ :api_method => @pubsub . projects . topics . list ,
682
+ :parameters => { 'project' => 'projects/12345' } ,
683
+ :connection => conn
684
+ )
685
+ conn . verify
686
+ end
687
+
688
+ it 'should correctly determine the service root_uri' do
689
+ expect ( @pubsub . root_uri . to_s ) . to eq ( 'https://pubsub.googleapis.com/' )
690
+ end
691
+ end
662
692
end
You can’t perform that action at this time.
0 commit comments