Skip to content

Commit 6dc1e30

Browse files
committed
fix: Reverse edge processing
1 parent a7179f2 commit 6dc1e30

File tree

2 files changed

+1
-103
lines changed

2 files changed

+1
-103
lines changed

lib/twilio-ruby/base/client_base.rb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ module REST
33
class ClientBase
44
# rubocop:disable Style/ClassVars
55
@@default_region = 'us1'
6-
# Maps region codes to their corresponding edge location names
7-
# Used to automatically set edge based on region for backward compatibility
8-
@@region_mappings = {
9-
'au1' => 'sydney',
10-
'br1' => 'sao-paulo',
11-
'de1' => 'frankfurt',
12-
'ie1' => 'dublin',
13-
'jp1' => 'tokyo',
14-
'jp2' => 'osaka',
15-
'sg1' => 'singapore',
16-
'us1' => 'ashburn',
17-
'us2' => 'umatilla'
18-
}
196
# rubocop:enable Style/ClassVars
207

218
attr_accessor :http_client, :username, :password, :account_sid, :auth_token, :region, :edge, :logger,
@@ -27,12 +14,7 @@ def initialize(username = nil, password = nil, account_sid = nil, region = nil,
2714
@username = username || Twilio.account_sid
2815
@password = password || Twilio.auth_token
2916
@region = region || Twilio.region
30-
if Twilio.edge
31-
@edge = Twilio.edge
32-
elsif @region && @@region_mappings[region]
33-
warn '[DEPRECATION] Setting default `Edge` for the provided `region`.'
34-
@edge = @@region_mappings[region]
35-
end
17+
@edge = Twilio.edge
3618
@account_sid = account_sid || @username
3719
@auth_token = @password
3820
@auth = [@username, @password]
@@ -96,15 +78,6 @@ def request(host, port, method, uri, params = {}, data = {}, headers = {}, auth
9678
##
9779
# Build the final request uri
9880
def build_uri(uri)
99-
if (@region.nil? && !@edge.nil?) || (!@region.nil? && @edge.nil?)
100-
# rubocop:disable Layout/LineLength
101-
warn '[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com;otherwise use product.twilio.com.'
102-
# rubocop:enable Layout/LineLength
103-
end
104-
if @edge.nil? && @region && @@region_mappings[@region]
105-
warn '[DEPRECATION] Setting default `Edge` for the provided `region`.'
106-
@edge = @@region_mappings[@region]
107-
end
10881
return uri if @region.nil? && @edge.nil?
10982

11083
parsed_url = URI(uri)

spec/rest/client_spec.rb

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,6 @@
88
end
99

1010
describe Twilio::REST::Client do
11-
context 'configuration of edge' do
12-
it 'uses the edge value from region map' do
13-
@client = Twilio::REST::Client.new('myUser', 'myPassword', nil, 'us1', 'myClient', 'myLogger')
14-
expect(@client.account_sid).to eq('myUser')
15-
expect(@client.auth_token).to eq('myPassword')
16-
expect(@client.http_client).to eq('myClient')
17-
expect(@client.region).to eq('us1')
18-
expect(@client.edge).to eq('ashburn')
19-
expect(@client.logger).to eq('myLogger')
20-
end
21-
22-
it 'uses the edge value from region map using setter' do
23-
@client = Twilio::REST::Client.new('myUser', 'myPassword', nil)
24-
@client.region = 'us1'
25-
@client.http_client = Twilio::HTTP::Client.new
26-
@connection = Faraday::Connection.new
27-
expect(Faraday).to receive(:new).and_yield(@connection).and_return(@connection)
28-
allow_any_instance_of(Faraday::Connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))
29-
@client.request('host', 'port', 'GET', 'https://api.twilio.com')
30-
expect(@client.region).to eq('us1')
31-
expect(@client.edge).to eq('ashburn')
32-
end
33-
34-
it 'catches warning when setting region in constructor' do
35-
original_stderr = $stderr
36-
$stderr = StringIO.new
37-
begin
38-
@client = Twilio::REST::Client.new('myUser', 'myPassword', 'someSid', 'ie1', 'myClient', 'myLogger')
39-
warn '[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.'
40-
warn '[DEPRECATION] Setting default `Edge` for the provided `region`.'
41-
warnings = $stderr.string
42-
expect(warnings).to include('[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.')
43-
expect(warnings).to include('[DEPRECATION] Setting default `Edge` for the provided `region`.')
44-
ensure
45-
$stderr = original_stderr
46-
end
47-
end
48-
49-
it 'catches warning when setting region' do
50-
original_stderr = $stderr
51-
$stderr = StringIO.new
52-
begin
53-
@client = Twilio::REST::Client.new('myUser', 'myPassword', 'someSid')
54-
@client.region = 'myRegion'
55-
warn '[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.'
56-
warn '[DEPRECATION] Setting default `Edge` for the provided `region`.'
57-
warnings = $stderr.string
58-
expect(warnings).to include('[DEPRECATION] For regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.')
59-
expect(warnings).to include('[DEPRECATION] Setting default `Edge` for the provided `region`.')
60-
ensure
61-
$stderr = original_stderr
62-
end
63-
end
64-
65-
it 'catches warning when setting edge' do
66-
Twilio.configure do |config|
67-
config.account_sid = 'someSid'
68-
config.auth_token = 'someToken'
69-
config.http_client = 'someClient'
70-
config.edge = 'someEdge'
71-
config.logger = 'someLogger'
72-
end
73-
original_stderr = $stderr
74-
$stderr = StringIO.new
75-
begin
76-
@client = Twilio::REST::Client.new('myUser', 'myPassword', 'someSid')
77-
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`.'
78-
warnings = $stderr.string
79-
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`.')
80-
ensure
81-
$stderr = original_stderr
82-
end
83-
end
84-
end
85-
8611
context 'configuration' do
8712
before do
8813
Twilio.configure do |config|

0 commit comments

Comments
 (0)