Skip to content

Commit a97e4bc

Browse files
committed
Merge pull request twilio#154 from philnash/encode-phone-number-lookups
URI encode phone number lookups
2 parents 28d3f8d + 4d7d9c2 commit a97e4bc

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/twilio-ruby/rest/lookups/phone_numbers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PhoneNumbers < Twilio::REST::NextGenListResource;
66
include Twilio::REST::Utils
77

88
def get(number, query={})
9-
full_path = "#{@path}/#{number}"
9+
full_path = "#{@path}/#{URI.encode(number)}"
1010
full_path << "?#{url_encode(twilify(query))}" if !query.empty?
1111
@instance_class.new full_path, @client
1212
end

spec/rest/lookups/phone_number_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,24 @@
55
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
66
expect(client).to respond_to(:phone_numbers)
77
end
8+
9+
it 'gets phone numbers without special encoding' do
10+
number = '+13123131434'
11+
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
12+
expect(client).to receive(:get).once
13+
.with('/v1/PhoneNumbers/+13123131434')
14+
.and_return({ phone_number: number })
15+
phone_number = client.phone_numbers.get('+13123131434').phone_number
16+
expect(phone_number).to be(number)
17+
end
18+
19+
it 'URI encodes phone number path parameters' do
20+
number = '+13123131434'
21+
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
22+
expect(client).to receive(:get).once
23+
.with('/v1/PhoneNumbers/+1%20312%20313%201434')
24+
.and_return({ phone_number: number })
25+
phone_number = client.phone_numbers.get('+1 312 313 1434').phone_number
26+
expect(phone_number).to be(number)
27+
end
828
end

0 commit comments

Comments
 (0)