diff --git a/lib/twilio-ruby/base/client_base.rb b/lib/twilio-ruby/base/client_base.rb index 7987cf9f0..304c5765f 100644 --- a/lib/twilio-ruby/base/client_base.rb +++ b/lib/twilio-ruby/base/client_base.rb @@ -27,15 +27,10 @@ def initialize(username = nil, password = nil, account_sid = nil, region = nil, @username = username || Twilio.account_sid @password = password || Twilio.auth_token @region = region || Twilio.region - if (region.nil? && !Twilio.edge.nil?) || (!region.nil? && Twilio.edge.nil?) - # rubocop:disable Layout/LineLength - warn '[DEPRECATION] For regional processing, DNS is of format product...twilio.com;otherwise use product.twilio.com.' - end if Twilio.edge @edge = Twilio.edge elsif @region && @@region_mappings[region] warn '[DEPRECATION] Setting default `Edge` for the provided `region`.' - # rubocop:enable Layout/LineLength @edge = @@region_mappings[region] end @account_sid = account_sid || @username @@ -101,6 +96,11 @@ def request(host, port, method, uri, params = {}, data = {}, headers = {}, auth ## # Build the final request uri def build_uri(uri) + if (@region.nil? && !@edge.nil?) || (!@region.nil? && @edge.nil?) + # rubocop:disable Layout/LineLength + warn '[DEPRECATION] For regional processing, DNS is of format product...twilio.com;otherwise use product.twilio.com.' + # rubocop:enable Layout/LineLength + end if @edge.nil? && @region && @@region_mappings[@region] warn '[DEPRECATION] Setting default `Edge` for the provided `region`.' @edge = @@region_mappings[@region] diff --git a/spec/rest/client_spec.rb b/spec/rest/client_spec.rb index 97230c521..39d08e978 100644 --- a/spec/rest/client_spec.rb +++ b/spec/rest/client_spec.rb @@ -31,7 +31,7 @@ expect(@client.edge).to eq('ashburn') end - it 'catches warning when setting region' do + it 'catches warning when setting region in constructor' do original_stderr = $stderr $stderr = StringIO.new begin @@ -46,6 +46,22 @@ end end + it 'catches warning when setting region' do + original_stderr = $stderr + $stderr = StringIO.new + begin + @client = Twilio::REST::Client.new('myUser', 'myPassword', 'someSid') + @client.region = 'myRegion' + warn '[DEPRECATION] For regional processing, DNS is of format product...twilio.com; otherwise use product.twilio.com.' + warn '[DEPRECATION] Setting default `Edge` for the provided `region`.' + warnings = $stderr.string + expect(warnings).to include('[DEPRECATION] For regional processing, DNS is of format product...twilio.com; otherwise use product.twilio.com.') + expect(warnings).to include('[DEPRECATION] Setting default `Edge` for the provided `region`.') + ensure + $stderr = original_stderr + end + end + it 'catches warning when setting edge' do Twilio.configure do |config| config.account_sid = 'someSid'