Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #154 from philnash/encode-phone-number-lookups
Browse files Browse the repository at this point in the history
URI encode phone number lookups
  • Loading branch information
philnash committed Jun 19, 2015
2 parents 28d3f8d + 4d7d9c2 commit a97e4bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/twilio-ruby/rest/lookups/phone_numbers.rb
Expand Up @@ -6,7 +6,7 @@ class PhoneNumbers < Twilio::REST::NextGenListResource;
include Twilio::REST::Utils

def get(number, query={})
full_path = "#{@path}/#{number}"
full_path = "#{@path}/#{URI.encode(number)}"
full_path << "?#{url_encode(twilify(query))}" if !query.empty?
@instance_class.new full_path, @client
end
Expand Down
20 changes: 20 additions & 0 deletions spec/rest/lookups/phone_number_spec.rb
Expand Up @@ -5,4 +5,24 @@
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
expect(client).to respond_to(:phone_numbers)
end

it 'gets phone numbers without special encoding' do
number = '+13123131434'
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
expect(client).to receive(:get).once
.with('/v1/PhoneNumbers/+13123131434')
.and_return({ phone_number: number })
phone_number = client.phone_numbers.get('+13123131434').phone_number
expect(phone_number).to be(number)
end

it 'URI encodes phone number path parameters' do
number = '+13123131434'
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
expect(client).to receive(:get).once
.with('/v1/PhoneNumbers/+1%20312%20313%201434')
.and_return({ phone_number: number })
phone_number = client.phone_numbers.get('+1 312 313 1434').phone_number
expect(phone_number).to be(number)
end
end

0 comments on commit a97e4bc

Please sign in to comment.