Skip to content

Commit

Permalink
add URI encoding for phone numbers (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
eshanholtz authored Nov 15, 2019
1 parent b828186 commit b33b438
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public PhoneNumber fetch(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.GET,
Domains.LOOKUPS.toString(),
"/v1/PhoneNumbers/" + this.pathPhoneNumber + "",
"/v1/PhoneNumbers/" + this.pathPhoneNumber.encode("utf-8") + "",
client.getRegion()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Number fetch(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.GET,
Domains.PRICING.toString(),
"/v1/Voice/Numbers/" + this.pathNumber + "",
"/v1/Voice/Numbers/" + this.pathNumber.encode("utf-8") + "",
client.getRegion()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Number fetch(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.GET,
Domains.PRICING.toString(),
"/v2/Voice/Numbers/" + this.pathDestinationNumber + "",
"/v2/Voice/Numbers/" + this.pathDestinationNumber.encode("utf-8") + "",
client.getRegion()
);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/twilio/type/PhoneNumber.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twilio.type;

import java.util.Objects;
import java.net.URLEncoder;

public class PhoneNumber implements Endpoint {
private final String rawNumber;
Expand Down Expand Up @@ -36,4 +37,13 @@ public int hashCode() {
public String toString() {
return this.rawNumber;
}

public String encode(String enc) {
try {
return URLEncoder.encode(this.rawNumber, enc);
}
catch (Exception e) {
return this.rawNumber;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testFetchRequest() {
new NonStrictExpectations() {{
Request request = new Request(HttpMethod.GET,
Domains.LOOKUPS.toString(),
"/v1/PhoneNumbers/+15017122661");
"/v1/PhoneNumbers/%2B15017122661");

twilioRestClient.request(request);
times = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testFetchRequest() {
new NonStrictExpectations() {{
Request request = new Request(HttpMethod.GET,
Domains.PRICING.toString(),
"/v1/Voice/Numbers/+15017122661");
"/v1/Voice/Numbers/%2B15017122661");

twilioRestClient.request(request);
times = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testFetchRequest() {
new NonStrictExpectations() {{
Request request = new Request(HttpMethod.GET,
Domains.PRICING.toString(),
"/v2/Voice/Numbers/+15017122661");
"/v2/Voice/Numbers/%2B15017122661");

twilioRestClient.request(request);
times = 1;
Expand Down

0 comments on commit b33b438

Please sign in to comment.