Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,32 @@
import java.util.function.Predicate;


/*
* Use this BearerToken Rest Client if no authentication is involved in an API.
/**
* The `BearerTokenTwilioRestClient` class is a specialized REST client for interacting with Twilio's API
* using JWT token-based authentication. It handles token management, request retries, and logging.
*
* <p>Features:</p>
* <ul>
* <li>Automatic token fetching and renewal when expired.</li>
* <li>Support for specifying Twilio's region and edge for global infrastructure.</li>
* <li>Customizable HTTP client and user-agent extensions.</li>
* <li>Detailed request and response logging for debugging purposes.</li>
* </ul>
*
* <p>Usage:</p>
* <pre>
* BearerTokenTwilioRestClient client = new BearerTokenTwilioRestClient.Builder()
* .region("us1")
* .edge("ashburn")
* .tokenManager(new CustomTokenManager())
* .build();
*
* BearerTokenRequest request = new BearerTokenRequest("GET", "/path");
* Response response = client.request(request);
* </pre>
*
* <p>Thread Safety:</p>
* This class is thread-safe for concurrent use.
*/
public class BearerTokenTwilioRestClient {
public static final int HTTP_STATUS_CODE_CREATED = 201;
Expand Down Expand Up @@ -54,7 +78,7 @@ private BearerTokenTwilioRestClient(BearerTokenTwilioRestClient.Builder b) {
// generates warnings from the module system on Java 9+
objectMapper.registerModule(new JavaTimeModule());
}

public static class Builder {
private String region;
private String edge;
Expand Down Expand Up @@ -111,7 +135,7 @@ public Response request(BearerTokenRequest request) {
}
}
}

request.setAuth(accessToken);
if (region != null)
request.setRegion(region);
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/com/twilio/http/noauth/NoAuthTwilioRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,36 @@
import java.util.function.Predicate;


/*
* Use this NoAuth Rest Client if no authentication is involved in an API.
/**
* The `NoAuthTwilioRestClient` class is a specialized REST client for interacting with Twilio's API
* when no authentication is required. It provides functionality for making API requests, logging,
* and customizing request parameters such as region, edge, and user-agent extensions.
*
* <p>Features:</p>
* <ul>
* <li>Support for specifying Twilio's region and edge for global infrastructure.</li>
* <li>Customizable HTTP client and user-agent extensions.</li>
* <li>Detailed request and response logging for debugging purposes.</li>
* </ul>
*
* <p>Usage:</p>
* <pre>
* NoAuthTwilioRestClient client = new NoAuthTwilioRestClient.Builder()
* .region("us1")
* .edge("ashburn")
* .build();
*
* NoAuthRequest request = new NoAuthRequest("GET", "/path");
* Response response = client.request(request);
* </pre>
*
* <p>Thread Safety:</p>
* This class is thread-safe for concurrent use as it does not maintain mutable shared state.
*/
public class NoAuthTwilioRestClient {
@Getter
private final ObjectMapper objectMapper;

@Getter
private final String region;
@Getter
Expand All @@ -47,7 +70,7 @@ private NoAuthTwilioRestClient(NoAuthTwilioRestClient.Builder b) {
// generates warnings from the module system on Java 9+
objectMapper.registerModule(new JavaTimeModule());
}

public static class Builder {
private String region;
private String edge;
Expand Down