From acb1097b7f9766a7cc2f056a4ca351c67014eaf2 Mon Sep 17 00:00:00 2001 From: Nick Dower Date: Fri, 23 Feb 2024 22:07:35 +0100 Subject: [PATCH] fix(core): allow BaseService#root_url to be an Addressable::URI (#17895) --- google-apis-core/lib/google/apis/core/base_service.rb | 6 +++--- google-apis-core/spec/google/apis/core/service_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index 416a7d449f8..22ee6553ce4 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -119,16 +119,16 @@ def universe_domain= new_ud end # Root URL (host/port) for the API - # @return [Addressable::URI] + # @return [Addressable::URI, String] attr_reader :root_url # Set the root URL. # If the given url includes a universe domain substitution, it is # resolved in the current universe domain # - # @param url_or_template [String] The URL, which can include a universe domain substitution + # @param url_or_template [Addressable::URI, String] The URL, which can include a universe domain substitution def root_url= url_or_template - if url_or_template.include? ENDPOINT_SUBSTITUTION + if url_or_template.is_a?(String) && url_or_template.include?(ENDPOINT_SUBSTITUTION) @root_url_template = url_or_template @root_url = url_or_template.gsub ENDPOINT_SUBSTITUTION, universe_domain else diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index 7650c85c36e..53167a12700 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -533,6 +533,11 @@ expect(service_ud.root_url).to eql "https://endpoint1.mydomain5.com/" end + it "should support setting root url to Addressable::URI" do + service_ud.root_url = Addressable::URI.parse("https://endpoint1.mydomain5.com/") + expect(service_ud.root_url).to be_a(Addressable::URI) + end + it "should support setting root url to a dynamic value" do service.universe_domain = "mydomain6.com" service.root_url = "https://endpoint2.$UNIVERSE_DOMAIN$/"