Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions lib/twilio-ruby/base/client_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ module REST
class ClientBase
# rubocop:disable Style/ClassVars
@@default_region = 'us1'
# Maps region codes to their corresponding edge location names
# Used to automatically set edge based on region for backward compatibility
@@region_mappings = {
'au1' => 'sydney',
'br1' => 'sao-paulo',
'de1' => 'frankfurt',
'ie1' => 'dublin',
'jp1' => 'tokyo',
'jp2' => 'osaka',
'sg1' => 'singapore',
'us1' => 'ashburn',
'us2' => 'umatilla'
}
# rubocop:enable Style/ClassVars

attr_accessor :http_client, :username, :password, :account_sid, :auth_token, :region, :edge, :logger,
Expand All @@ -27,12 +14,7 @@ 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 Twilio.edge
@edge = Twilio.edge
elsif @region && @@region_mappings[region]
warn '[DEPRECATION] Setting default `Edge` for the provided `region`.'
@edge = @@region_mappings[region]
end
@edge = Twilio.edge
@account_sid = account_sid || @username
@auth_token = @password
@auth = [@username, @password]
Expand Down Expand Up @@ -96,15 +78,6 @@ 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.<edge>.<region>.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]
end
return uri if @region.nil? && @edge.nil?

parsed_url = URI(uri)
Expand Down
75 changes: 0 additions & 75 deletions spec/rest/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,6 @@
end

describe Twilio::REST::Client do
context 'configuration of edge' do
it 'uses the edge value from region map' do
@client = Twilio::REST::Client.new('myUser', 'myPassword', nil, 'us1', 'myClient', 'myLogger')
expect(@client.account_sid).to eq('myUser')
expect(@client.auth_token).to eq('myPassword')
expect(@client.http_client).to eq('myClient')
expect(@client.region).to eq('us1')
expect(@client.edge).to eq('ashburn')
expect(@client.logger).to eq('myLogger')
end

it 'uses the edge value from region map using setter' do
@client = Twilio::REST::Client.new('myUser', 'myPassword', nil)
@client.region = 'us1'
@client.http_client = Twilio::HTTP::Client.new
@connection = Faraday::Connection.new
expect(Faraday).to receive(:new).and_yield(@connection).and_return(@connection)
allow_any_instance_of(Faraday::Connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))
@client.request('host', 'port', 'GET', 'https://api.twilio.com')
expect(@client.region).to eq('us1')
expect(@client.edge).to eq('ashburn')
end

it 'catches warning when setting region in constructor' do
original_stderr = $stderr
$stderr = StringIO.new
begin
@client = Twilio::REST::Client.new('myUser', 'myPassword', 'someSid', 'ie1', 'myClient', 'myLogger')
warn '[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.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.<edge>.<region>.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 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.<edge>.<region>.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.<edge>.<region>.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'
config.auth_token = 'someToken'
config.http_client = 'someClient'
config.edge = 'someEdge'
config.logger = 'someLogger'
end
original_stderr = $stderr
$stderr = StringIO.new
begin
@client = Twilio::REST::Client.new('myUser', 'myPassword', 'someSid')
warn '[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.+[DEPRECATION] Setting default `Edge` for the provided `region`.'
warnings = $stderr.string
expect(warnings).to include('[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.+[DEPRECATION] Setting default `Edge` for the provided `region`.')
ensure
$stderr = original_stderr
end
end
end

context 'configuration' do
before do
Twilio.configure do |config|
Expand Down
Loading