Skip to content

Commit

Permalink
chore: added preview messaging domain url (#752)
Browse files Browse the repository at this point in the history
* added preview messaging domain url
  • Loading branch information
sbansla authored Jun 27, 2023
1 parent 7ebbd27 commit 954954f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/twilio/Domains.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum Domains {
NUMBERS("numbers"),
OAUTH("oauth"),
PREVIEW("preview"),
PREVIEWMESSAGING("preview.messaging"),
PRICING("pricing"),
PROXY("proxy"),
ROUTES("routes"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;

public class Enum {
public class EnumConstants {

@Getter
@RequiredArgsConstructor
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/twilio/http/NetworkHttpClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.twilio.http;

import com.twilio.Twilio;
import com.twilio.constant.Enum;
import com.twilio.constant.EnumConstants;
import com.twilio.exception.ApiException;

import java.io.IOException;
Expand Down Expand Up @@ -127,15 +127,15 @@ public Response makeRequest(final Request request) {

if (method == HttpMethod.POST) {
// TODO: It will be removed after one RC Release.
if (request.getContentType() == null) request.setContentType(Enum.ContentType.FORM_URLENCODED);
if (Enum.ContentType.JSON.getValue().equals(request.getContentType().getValue())) {
if (request.getContentType() == null) request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
if (EnumConstants.ContentType.JSON.getValue().equals(request.getContentType().getValue())) {
HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON);
builder.setEntity(entity);
builder.addHeader(
HttpHeaders.CONTENT_TYPE, Enum.ContentType.JSON.getValue());
HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.JSON.getValue());
} else {
builder.addHeader(
HttpHeaders.CONTENT_TYPE, Enum.ContentType.FORM_URLENCODED.getValue());
HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.FORM_URLENCODED.getValue());
for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) {
for (String value : entry.getValue()) {
builder.addParameter(entry.getKey(), value);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/twilio/http/Request.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.twilio.http;

import com.twilio.constant.Enum;
import com.twilio.constant.EnumConstants;
import com.twilio.exception.ApiException;
import com.twilio.exception.InvalidRequestException;

Expand Down Expand Up @@ -37,7 +37,7 @@ public class Request {

private List<String> userAgentExtensions;

private Enum.ContentType contentType;
private EnumConstants.ContentType contentType;

private String body;

Expand Down Expand Up @@ -117,11 +117,11 @@ public List<String> getUserAgentExtensions() {
return this.userAgentExtensions;
}

public Enum.ContentType getContentType() {
public EnumConstants.ContentType getContentType() {
return contentType;
}

public void setContentType(Enum.ContentType contentType) {
public void setContentType(EnumConstants.ContentType contentType) {
this.contentType = contentType;
}

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

import com.twilio.Twilio;
import com.twilio.constant.Enum;
import com.twilio.constant.EnumConstants;
import com.twilio.exception.ApiException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
Expand Down Expand Up @@ -109,15 +109,15 @@ public Response makeRequest(Request request) {
HttpMethod method = request.getMethod();
if (method == HttpMethod.POST) {
// TODO: It will be removed after one RC Release.
if (request.getContentType() == null) request.setContentType(Enum.ContentType.FORM_URLENCODED);
if (Enum.ContentType.JSON.getValue().equals(request.getContentType().getValue())) {
if (request.getContentType() == null) request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
if (EnumConstants.ContentType.JSON.getValue().equals(request.getContentType().getValue())) {
HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON);
builder.setEntity(entity);
builder.addHeader(
HttpHeaders.CONTENT_TYPE, Enum.ContentType.JSON.getValue());
HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.JSON.getValue());
} else {
builder.addHeader(
HttpHeaders.CONTENT_TYPE, Enum.ContentType.FORM_URLENCODED.getValue());
HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.FORM_URLENCODED.getValue());
for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) {
for (String value : entry.getValue()) {
builder.addParameter(entry.getKey(), value);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/twilio/http/NetworkHttpClientTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.twilio.http;

import com.twilio.constant.Enum;
import com.twilio.constant.EnumConstants;
import com.twilio.exception.ApiConnectionException;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -67,7 +67,7 @@ private void setup(
when(mockRequest.constructURL()).thenReturn(new URL("http://foo.com/hello"));
when(mockRequest.requiresAuthentication()).thenReturn(requiresAuthentication);
when(mockRequest.getAuthString()).thenReturn("foo:bar");
when(mockRequest.getContentType()).thenReturn(Enum.ContentType.FORM_URLENCODED);
when(mockRequest.getContentType()).thenReturn(EnumConstants.ContentType.FORM_URLENCODED);
when(mockClient.execute(any())).thenReturn(mockResponse);
when(mockEntity.isRepeatable()).thenReturn(true);
when(mockEntity.getContentLength()).thenReturn(1L);
Expand Down Expand Up @@ -115,7 +115,7 @@ public void testPost() throws IOException {
@Test
public void testJsonPost() throws IOException {
setup(201, "frobozz", HttpMethod.POST, false);
when(mockRequest.getContentType()).thenReturn(Enum.ContentType.JSON);
when(mockRequest.getContentType()).thenReturn(EnumConstants.ContentType.JSON);
String body = "{\"from\":\"+12345\",\"body\":\"message body\",\"messages\":[{\"to\":\"+12345\"}]}";
when(mockRequest.getBody()).thenReturn(body);
Response resp = client.makeRequest(mockRequest);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/twilio/http/RequestTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.twilio.http;

import com.twilio.constant.Enum;
import com.twilio.constant.EnumConstants;
import com.twilio.exception.ApiException;
import com.twilio.rest.Domains;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -321,7 +321,7 @@ public void testEquals() {
@Test
public void testContentType() {
Request r = new Request(HttpMethod.POST, "http://example.com/foobar");
r.setContentType(Enum.ContentType.JSON);
assertEquals(Enum.ContentType.JSON, r.getContentType());
r.setContentType(EnumConstants.ContentType.JSON);
assertEquals(EnumConstants.ContentType.JSON, r.getContentType());
}
}
6 changes: 3 additions & 3 deletions src/test/java/com/twilio/http/ValidationClientTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.twilio.http;

import com.twilio.constant.Enum;
import com.twilio.constant.EnumConstants;
import org.junit.Test;

import java.security.KeyPair;
Expand Down Expand Up @@ -59,14 +59,14 @@ private void testContentType(final HttpMethod httpMethod) throws Exception {
final HttpUrl url = server.url(path);
final ValidationClient client = new ValidationClient("dummy-sid1", "dummy-sid2", "dummy-signing-key", keyPair.getPrivate());
final Request request = new Request(httpMethod, url.url().toString());
request.setContentType(Enum.ContentType.JSON);
request.setContentType(EnumConstants.ContentType.JSON);
String body = "{\"from\":\"+12345\",\"body\":\"message body\",\"messages\":[{\"to\":\"+12345\"}]}";
request.setBody(body);
final Response response = client.makeRequest(request);
assertEquals(200, response.getStatusCode());
final RecordedRequest recordedRequest = server.takeRequest();
assertEquals(httpMethod.name(), recordedRequest.getMethod());
assertEquals(Enum.ContentType.JSON.getValue(), recordedRequest.getHeader("Content-Type"));
assertEquals(EnumConstants.ContentType.JSON.getValue(), recordedRequest.getHeader("Content-Type"));
final String validationHeaderValue = recordedRequest.getHeader("Twilio-Client-Validation");
assertNotNull(validationHeaderValue);
assertTrue(validationHeaderValue.length() > 0);
Expand Down

0 comments on commit 954954f

Please sign in to comment.