Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Merging 10rc branch to main #777

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ff36bd4
feat: support json content in requests (#746)
shrutiburman Jun 7, 2023
6a90931
[Librarian] Regenerated @ 0430a9c977225d55252b84f4d16e16ad2091cde1
twilio-dx Jun 15, 2023
81d85c7
Release 9.7.0
twilio-dx Jun 15, 2023
7ebbd27
feat: Enable json request body (#749)
sbansla Jun 26, 2023
954954f
chore: added preview messaging domain url (#752)
sbansla Jun 27, 2023
5307f9a
chore: enabling branch for 10.0.0-rc.1 release (#751)
sbansla Jun 27, 2023
3b31008
chore: corrected rc version for release
sbansla Jul 4, 2023
e4711a4
[Librarian] Regenerated @ 6ed189cbba23e3c77c423ac17bd7bfccfc88b126 27…
twilio-dx Jul 4, 2023
8aa8f48
Release 10.0.0-rc.1
twilio-dx Jul 4, 2023
5c9a366
[Librarian] Regenerated @ 07a9a183b1077d5a881e6cd53ef76b0d75ccc6b0 46…
twilio-dx Jul 27, 2023
c5e6585
Release 10.0.0-rc.2
twilio-dx Jul 27, 2023
bb5458a
[Librarian] Regenerated @ 1e94599903f1dbac80d3040ebbdba7d3f7fb074d 6a…
twilio-dx Aug 10, 2023
b573f61
Release 10.0.0-rc.3
twilio-dx Aug 10, 2023
c4e73e4
[Librarian] Regenerated @ 38fb28edc02f73b8635b45a5612c5ae33eab39fe 54…
twilio-dx Aug 24, 2023
9da3278
Release 10.0.0-rc.4
twilio-dx Aug 24, 2023
7a8223f
Validate ssl method update (#767)
AsabuHere Oct 6, 2023
48e68fa
chore: add-constructor-apiexception (#772)
sbansla Oct 19, 2023
8fa3a8d
[Librarian] Regenerated @ 922c1fef02b8c8fbbbe2315aa9b9d1dba49f3fc0 5b…
twilio-dx Oct 19, 2023
3508d6e
Release 10.0.0-rc.5
twilio-dx Oct 19, 2023
a3dda32
[Librarian] Regenerated @ 5eb406c4977c9f6976e6053cb5b581056f541a59 5a…
twilio-dx Nov 6, 2023
3e14d3c
Release 10.0.0-rc.6
twilio-dx Nov 6, 2023
ca53135
chore: updating latest changes
sbansla Feb 7, 2024
539a01b
chore: written readme and upgrade guide
sbansla Feb 7, 2024
729b11f
prettier output
sbansla Feb 7, 2024
f2d2641
latest oai rc changes
sbansla Feb 8, 2024
74b3296
prettier run
sbansla Feb 8, 2024
c5883b5
chore: latest oai changes
sbansla Feb 8, 2024
eb00438
updated changes
sbansla Feb 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
twilio-java changelog
=====================

[2023-06-15] Version 9.7.0
--------------------------
**Api**
- Added `content_sid` as conditional parameter
- Removed `content_sid` as optional field **(breaking change)**

**Insights**
- Added `annotation` to list summary output


[2023-06-01] Version 9.6.2
--------------------------
**Api**
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ Use the following dependency in your project to grab via Maven:
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>9.X.X</version>
<version>10.X.X</version>
<scope>compile</scope>
</dependency>
```

or Gradle:

```groovy
implementation "com.twilio.sdk:twilio:9.X.X"
implementation "com.twilio.sdk:twilio:10.X.X"
```

If you want to compile it yourself, here's how:
Expand Down
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

_`MAJOR` version bumps will have upgrade notes posted here._

[2024-02-08] 9.x.x to 10.x.x
### Overview

##### Twilio Java Helper Library’s major version 10.0.0 is now available. We ensured that you can upgrade to Java helper Library 10.0.0 version without any breaking changes of existing apis

Behind the scenes Java Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages.
We're pleased to inform you that version 10.0.0 adds support for the application/json content type in the request body.

[2022-09-21] 8.x.x to 9.x.x
-----------------------------
### Overview
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>twilio</artifactId>
<packaging>jar</packaging>
<name>twilio</name>
<version>9.6.2</version>
<version>10.0.0-rc.6</version>
<description>Twilio Java Helper Library</description>
<url>https://www.twilio.com</url>
<licenses>
Expand All @@ -19,7 +19,7 @@
<url>[email protected]:twilio/twilio-java.git</url>
<connection>scm:git:[email protected]:twilio/twilio-java.git</connection>
<developerConnection>scm:git:[email protected]:twilio/twilio-java.git</developerConnection>
<tag>9.6.2</tag>
<tag>10.0.0-rc.6</tag>
</scm>
<developers>
<developer>
Expand Down Expand Up @@ -323,8 +323,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>9</source>
<target>9</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
Expand Down
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 @@ -26,6 +26,7 @@ public enum Domains {
IPMESSAGING("ip-messaging"),
LOOKUPS("lookups"),
MEDIA("media"),
PREVIEWMESSAGING("preview.messaging"),
MESSAGING("messaging"),
MICROVISOR("microvisor"),
MONITOR("monitor"),
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/twilio/Twilio.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class Twilio {

public static final String VERSION = "9.6.2";
public static final String VERSION = "10.0.0-rc.6";
public static final String JAVA_VERSION = System.getProperty("java.version");
public static final String OS_NAME = System.getProperty("os.name");
public static final String OS_ARCH = System.getProperty("os.arch");
Expand Down Expand Up @@ -241,7 +241,7 @@ public static void setExecutorService(final ExecutorService executorService) {
}

/**
* Validate that we can connect to the new SSL certificate posted on api.twilio.com.
* Validate that we can connect to the new SSL certificate posted on tls-test.twilio.com
*
* @throws CertificateValidationException if the connection fails
*/
Expand All @@ -252,7 +252,7 @@ public static void validateSslCertificate() {


public static void validateSslCertificate(NetworkHttpClient client) {
final Request request = new Request(HttpMethod.GET, "https://api.twilio.com:8443");
final Request request = new Request(HttpMethod.GET, "https://tls-test.twilio.com:443");
try {
final Response response = client.makeRequest(request);

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/twilio/constant/EnumConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.twilio.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

public class EnumConstants {

@Getter
@RequiredArgsConstructor
public enum ContentType {
JSON("application/json"),
FORM_URLENCODED("application/x-www-form-urlencoded");

private final String value;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/twilio/converter/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Converter {
* @param map map to convert
* @return converted JSON string
*/
public static String mapToJson(final Map<String, Object> map) {
public static String mapToJson(final Map<String, ? extends Object> map) {
try {
return MAPPER.writeValueAsString(map);
} catch (JsonProcessingException e) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/twilio/exception/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public ApiException(final String message, final Throwable cause) {
this(message, null, null, null, cause);
}

/**
* Create a new API Exception.
*
* @param message exception message
* @param status status code
*/
public ApiException(final String message, final Integer status) {
this(message, null, null, status, null);
}

/**
* Create a new API Exception.
*
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/com/twilio/http/NetworkHttpClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twilio.http;

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

import java.io.IOException;
Expand All @@ -19,6 +20,8 @@
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.config.SocketConfig;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;
Expand Down Expand Up @@ -123,13 +126,23 @@ public Response makeRequest(final Request request) {
}

if (method == HttpMethod.POST) {
builder.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");

for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) {
for (String value : entry.getValue()) {
builder.addParameter(entry.getKey(), value);
// TODO: It will be removed after one RC Release.
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, EnumConstants.ContentType.JSON.getValue());
} else {
builder.addHeader(
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);
}
}
}

}
builder.addHeader(HttpHeaders.USER_AGENT, HttpUtility.getUserAgentString(request.getUserAgentExtensions(), isCustomClient));

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

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

import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Request {
Expand All @@ -37,6 +37,10 @@ public class Request {

private List<String> userAgentExtensions;

private EnumConstants.ContentType contentType;

private String body;

/**
* Create a new API request.
*
Expand Down Expand Up @@ -113,6 +117,22 @@ public List<String> getUserAgentExtensions() {
return this.userAgentExtensions;
}

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

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

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

/**
* Create auth string from username and password.
*
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/com/twilio/http/ValidationClient.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.twilio.http;

import com.twilio.Twilio;
import com.twilio.constant.EnumConstants;
import com.twilio.exception.ApiException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.config.SocketConfig;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;
Expand Down Expand Up @@ -104,11 +108,20 @@ public Response makeRequest(Request request) {

HttpMethod method = request.getMethod();
if (method == HttpMethod.POST) {
builder.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");

for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) {
for (String value : entry.getValue()) {
builder.addParameter(entry.getKey(), value);
// TODO: It will be removed after one RC Release.
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, EnumConstants.ContentType.JSON.getValue());
} else {
builder.addHeader(
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
Loading
Loading